In shell, how to group the numbers in $foo as 1-3,6-8,11,13-17 Answer As an alternative, you can use this awk command: Now run it as: Here is an one-liner for doing the same: In this awk command we keep 2 variables: p for storing previous line’s number s for storing start of the range that need to be printed How
Tag: awk
truncate shell command output from last line matching a string until EOF
I would like to truncate the output of a shell script and only print the part between the last line matching a string/regex and EOF. E.g when running letsencrypt certbot renew –post-hook “service apache2 reload; service nginx reload” I get something like Now what I want to have is everything after the last ——- line, so the desired result would
edit the only lines which matches some word
I have to search a file for lines with some specific words and edit these lines as follows. The other lines should remain the same. For example: to be modified to: Can any one please help how to use AWK to achieve this. Regards Answer awk solution: Explanation: When brz or jp matches, save last field in last, remove last
How to print the last line of each ID?
I have a list of IDs (exon) each with multiple suffixes and I want to get the last line of each ID Input: Desired output: Answer
Shell script to edit and add a entry in file
Could any one help me to add entry at the end of the line. This is linux os. Below is the contents of the file /boot/grub2/grub.cfg I need to add entry at the end of the line “text1” and “text2”. after edit my file should look like: Answer With sed expression:
Awk in loopwith different file
I have four files and want to run a awk code on each file. But this code is not working. My code: Answer Awk can work with multiple files no need of for syntax will be like this or In your case To correct your existing code change To
extract multiple blocks of text to a new file
I need help extracting blocks of information from a single text file into new files or some form where I can manipulate the data from each block. Example: I need to be able to display and/or manipulate the variables (which I can do if I can isolate the right one). I don’t mind writing each one of these blocks to
Sed/awk: Aligning words in a file
I have a file with the following structure: I want to add another item to the file, using sed or awk: etc. So my next item looks like this: The column values is jagged. How do I align my values to the left like for previous items? I can see 2 solutions here: To align the values while inserting them
grep issues when using two files – I’ve tried everything
I have two files (recode and reads) that were built and saved with nano command and I want to compare what has on recode to reads and extract the lines in reads that overlaps. I have been trying to create a when loop with the previous logic on mind, but without success so far. The output data is not matching
Remove duplicates and keep line which contains max value from one column – LINUX
everyone! I’d like to remove duplicates and keep lines with the highest value from one column (4th column) in a file with 4 fields. I must do this in a Linux server. Before After Thank you so much and I’m sorry if I asked something repeated! But I didn’t find an answer for my problem. Answer You can try this,