Skip to main content

All Questions

1 vote
3 answers
84 views

Loop ip list through geoiplookup and delete lines that do not match criteria

Thanks in advance for any ideas you present. My current project has me trying to loop a file containing a list of 1000's of IP addresses through geoiplookup and piping it to sed to delete all lines ...
user avatar
2 votes
3 answers
86 views

Printing a specific section everytime search results are matched

I have a pretty basic text file on a Linux machine that has stuff like Chapters, Dialogues and References. This is what it looks like Chapter: 1 One: Birds and Trees Birds are beautiful and trees ...
learningregularexpressions's user avatar
-1 votes
5 answers
301 views

Delete all lines after n lines below the line containing the first match

If a file contains the following: Line 1 FooLine 5 Line 2 Line 55 Line 3 Line 4 Line 5 Line 6 Line 7 Line 5 Line 8 Line 9 How to delete the lines below two lines after "Line 5", so that the ...
Sadi's user avatar
  • 515
6 votes
13 answers
2k views

UNIX command to add comma and space

I have a file that looks like $ cat IP 10.3.1.1 10.4.1.1 10.6.3.1 10.19.4.2 10.22.3.4 How do I make it look like: $ cat IP 10.3.1.1, 10.4.1.1, 10.6.3.1, 10.19.4.2, 10.22.3.4
Shahriar Flamneco's user avatar
0 votes
5 answers
1k views

Delete lines below, excluding the line with match pattern

One can use sed '/pattern/Q' or sed '/pattern/,$d' to delete lines below a match pattern, but it also deletes the line containing the match pattern. How to exclude the line containing the match ...
Sadi's user avatar
  • 515
0 votes
6 answers
289 views

Delete all lines before n lines above the line containing the first match

If a file contains the following: Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 How to delete the lines above two lines before "Line 5", so that the file will now contain ...
Sadi's user avatar
  • 515
1 vote
2 answers
212 views

Need help with a sed script for specific word replacements in a text file

I'm trying to automate a specific text replacement task for Romanian text using sed or any other suitable Unix tool. Here are my requirements: Replace all instances of the letter â with î inside ...
Mafsi's user avatar
  • 141
-1 votes
1 answer
62 views

comparing multiple column values between two files

I have two CSV files on a Linux machine, containing data as: File A Sunil,21,write a line,2312,12-03-2022 Ashok,22,write a para,2312,12-03-2022 Sam,23,create file using,2312,12-03-2022 FileB 21,...
amit10504's user avatar
2 votes
4 answers
700 views

Count lines ending in "*"

I have several files in a directory with this kind of content: Wood * Nails Large Hammer * Some names have a star after them, some don't. I have multiple files with such content. In each file a ...
math101's user avatar
  • 51
0 votes
1 answer
147 views

Permutation with bash - Spread Five over Eight

Assuming I have the values A B C D E and eight places 1 2 3 4 5 6 7 8. How can I get all possible combinations printed with two- and three-time repetitions? Example: 1 2 3 4 5 6 7 8 _______________ A ...
nath's user avatar
  • 6,074
0 votes
1 answer
5k views

add a new line after a specific string in a file? [duplicate]

Right now I'm using echo sed '/\Random/a \ newly added line' info.txt to append some text to a file but I also need to add text below a certain string let's say random, I know it is possible with ...
Nawaz Moin yaakuza's user avatar
-4 votes
1 answer
637 views

Edit ntp.conf file using bash script to comment and replace lines

The output of current /etc/ntp.conf file in Debian 11: # /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help driftfile /var/lib/ntp/ntp.drift # Leap seconds definition provided by tzdata ...
Cruise5's user avatar
  • 546
2 votes
4 answers
1k views

Merge multiple rows into single row then append to csv output file

I have multiple comma-separated files that I need first to merge the rows into a single row then I can append that row to append to one output.csv file. file-1.txt: CV-1999-0001, CV-1999-0002, CV-1999-...
Denis Kisina's user avatar
1 vote
5 answers
7k views

Sed to replace text that comes after match

I was working it with awk, and keying on $1 $2 fields, but awk would act differently depending on whether the FieldSeperator ($match) starts the line, or had a blank before it, or didn't have a blank ...
Jamie Duquette's user avatar
2 votes
2 answers
886 views

Comparing with csv file value

I have a csv file and I need to compare the value in 4th column of 2nd row with a string. Sample csv file: Col1,Col2,Col3,Col4 Val1,Val2,Val3,ValNeeded I'm using the below code to perform this, ...
nishitha.m's user avatar

15 30 50 per page
1
2 3 4 5
13