awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

0
votes
1answer
7 views

split line based on space and delete the second part

I have a big file >fid|29290408|locus|VBIEntCas2262_0001| Phosphoglycolate phosphatase (EC 3.1.3.18) [Enterococcus casseliflavus EC20] ...
3
votes
4answers
2k views

Removing unwanted lines in text file

All I need is the sed or awk code to remove the even numbered lines in a text file. Nothing fancy I just need to remove irrelevant data on the even lines of a text file.
-1
votes
1answer
20 views

multiple input in a awk file

Please guide me to get out of it. Thanks in advance. I am having a situation that I have to write a awk script which takes the input of two .out files and generate a single .txt file. $ cat ...
3
votes
7answers
216 views

can we print the last word of each line in linux using sed command?

suppose , if there is a file consisting of following lines , if they are 12345 567 7878 66 er3 t45t y6y46y 4y6 y656y y5y 46y6 65y7 y66uyuy yy46y6y The output has to look like: 66 ...
0
votes
2answers
55 views

How to convert Log file to CSV using bash

Is it possible to turn this log entry into a properly formatted csv file using sed/awk? I've tried multiple ways to do this using sed/awk. Alas I couldn't do it. Before I do it in perl. is this ...
0
votes
1answer
13 views

Insert space at specified position in a file

I have this sample file: 234234|111||J1X0H8|SERP||R|D|666|M 234235|222||J1X0N5|SERP||C||555|M For each line, I need to insert a space after the 3rd character of the 4th column, like so: ...
1
vote
1answer
34 views

Monitor and alert user when stty settings change?

A particularly large (~10^6 LOC) program causes my stty settings to change from echo ixon icanon to -echo -ixon -icanon and I would like to find the function in this massive program that causes this ...
0
votes
0answers
16 views

Awk - Take $4$3$2 from Line 01 and $4 from Line 07 and Create a matching key

Any help is greatly appriciated. Desired Matching Key: $4$3$2 from line 01 and $4 from line 07 of A.txt Example: In A.txt $4=5000, $3=68, $2=89 in line 01 and $4=RT0429 or RT0428 or RT0588 in line ...
2
votes
3answers
58 views

Replace multiline string in files

I have a number of files I want to update by replacing one multi-line string with another multi-line string. Something along the lines of: * Some text, * something else * another thing And I want ...
3
votes
2answers
721 views

Split log file by time range

I have a log file and would like to cut it into copies of 15min. In the log file the lines start with: dd mmm yyyy hh:mm:ss,xxx e.g. 12 Feb 2013 16:05:02,xxx log text... and the file rotates ...
3
votes
2answers
108 views

Assign specific line from a variable to another variable

I would like to take a specific line from a variable to another variable. I tried this but it doesn't work: c="1.apple 2.banna 3.peach" read "Please choose fruit [1-3]:" t a=$c | awk "NR==$t" echo ...
0
votes
2answers
20 views

Get all the records from a file with Date collumn less than a month

Input file ID,Name,join_date 21433432,rds,2014_02_01 2131321,ABCDS,2014-10-20 2432745314,ASRER, 2015-01-20 2132432423,safdsad, 2015-12-30 Need two files created one for records with the date column ...
1
vote
2answers
44 views

awk manipulation

I have a file like this SRR959756.1081725 1 RNU2-54P:112:133:hsa-miR-1246 SRR959756.1162547 1 RNU2-54P:112:133:hsa-miR-1246 SRR959756.128602 2 ...
4
votes
3answers
42 views

How to select first occurrence between two patterns including them

How can I select first occurrence between two patterns including them. Preferably using sed or awk. I have: text something P1 something content1 content2 something P2 something text something P1 ...
1
vote
1answer
64 views

Searching file based on data range

I previously posted requesting help with counting occurrences of a string. I'm now hoping to search for the occurrence of a string within a range of values and print out a similarly formatted file ...
-3
votes
1answer
32 views

Empty columns which were seen before

I have a large CSV file and want to empty certain columns if they were seen before. So I have (to illustrate my problem): Category | Subcategory ---------+------------ foo | bar foo | bar ...
4
votes
2answers
42 views

How to print matching value of patterned field separator in AWK

In the below command, cat abc.txt|awk -F"[0-9]+." '{print FS $3}' Here FS prints [0-9]+.. However, I want the awk to print the matched value by that field separator e.g. "99." . Any idea how can ...
0
votes
2answers
30 views

Multiply a column using awk

How do I multiply a column by an integer (say 3) and replace the older value by new one, using awk? Input: Data 9390.900391 10573.089844 80.000000 200.000000 2.700000 Data ...
1
vote
2answers
46 views

Formatting ifconfig using sed/awk

I'm using ifconfig on OpenSUSE. When I run ifconfig eth0 I get eth0 Link encap:Ethernet HWaddr CE:FD:75:DF:A5:6D inet addr:172.16.4.177 Bcast:172.16.5.255 Mask:255.255.254.0 inet6 ...
8
votes
6answers
22k views

Show sum of file sizes in directory listing

The Windows dir directory listing command has a line at the end showing the total amount of space taken up by the files listed. For example, dir *.exe shows all the .exe files in the current ...
1
vote
2answers
62 views

Multiple File Redirection with awk and find

I have some files in a directory. And I want to add some lines at top and end of file using awk. Example: My awk command: awk 'BEGIN { print "line1\nline2" } { print $0 } END { print "line3\nline4" ...
2
votes
3answers
91 views

How can I insert the contents of a file into a string in bash

I would like to append the contents of a multi-line text file after a particular line in a string. For example, if the file file.txt contains line 1 line 2 I'd like do so something like printf ...
1
vote
1answer
19 views

Compare two Arrays in KSH and output the difference

I am not extremely familiar with KSH (Actually just started using it) and I am having problems with trying to create a script that will essentially compare two arrays that have been stored and then ...
-5
votes
0answers
41 views
-4
votes
1answer
62 views

Merge two csvfiles by column header

I have two csv files: success.csv "ID","Legacy ID","Field1", "Field2" 1,1111,google,news 2,2222,yahoo,news error.csv "Legacy ID","Field1","Field2","Message" 3333,aol,news,"Failed to upload ...
3
votes
4answers
119 views

How to swap entire html blocks in multiple files with sed

I have tons of html pages with a simlar content as follows: <div class="wrapper"> <div class="aaa"> ...lot of html1 here like div's/spans etc.. </div> <!-- end aaa --> ...
35
votes
2answers
50k views

How can I replace a string in a file(s)?

Replacing strings in files based on certain search criteria is a very common task. How can I replace string foo with bar in all files in the current directory? do the same recursively for sub ...
29
votes
10answers
41k views

Is there a way to get the min, max, median, and average of a list of numbers in a single command?

I have a list of numbers in a file, one per line. How can I get the minimum, maximum, median and average values? I want to use the results in a bash script. Although my immediate situation is for ...
3
votes
5answers
232 views

Awk - output the second line of a number of .dat files to one file

I have searched through previously asked questions and can't find an answer to what I am trying to do. note, I am new to linux. I have multiple files something like: (in reality i have 80) file1.dat ...
1
vote
6answers
5k views

Extract substring using regular expression on a Unix file

I have file with below contents . /ABC/RTE/AD_900_VOP_123/OPP /ABC/RTE/TRE/AD_900_VOP_145/BBB /ABC/RTE/AN_900_VFP_124/FBF /ABC/RTE/HD_900_FOP_153/WEW /ABD/RDV/AD_900_VOP_123/OPP ...
2
votes
2answers
75 views

Extracting values from a file keyed by multiple keys

Consider a file with key=value pairs, and each key is optionally a concatenation of multiple keys. In other words, many keys can map to one value. The reason behind this is that each key is a ...
3
votes
1answer
38 views

Filter out inconsistent data blocks

I would like to filter out rows that has inconsistent geno values in line-part blocks. In case of duplicate consistent values , I would just keep the first row. As example, 'gf345 part1' has more ...
0
votes
1answer
24 views

For value falls within a range get corresponding value

I am thinking to use awk to search a value from input file in a reference file and get a corresponding value from reference file. Both reference and input files can be sorted based on $3 and $2 ...
1
vote
1answer
67 views

Awk compare 2 files, print match together with non match lines filled with 0

I have two files. I want to match the 1st column of first file to 1st column of second file. If there is a match I'd like to print the 2st column of second file, if not 0. I have tried awk (awk ...
1
vote
2answers
41 views

splitting a file by column number

I have a file with 10,671 columns. I am trying to split it into 10 smaller files, each with 1000 columns until all columns have been printed, named file_transposed01, file_transposed02, ... ...
3
votes
4answers
463 views

Aggregate and group text file in perl or bash

I have a big text file(with 5m lines) in this format(4 columns, separated by ;): string1; string2; string3; userId The first 3 strings (SHA1s) form a single ID, called appId (so it can be ...
0
votes
2answers
37 views

Rearranging data in file with awk

I have a table ID Comment Statement 1 hi hello 2 hi hello 1 cya bye 1 k ok 2 kk ok How would one go about producing a result ...
2
votes
4answers
54 views

Rename mp3 file names to a pattern

I have a list of like names likes so: /A/B/C/D/E/F/filename_album1-003.mp3 its more like album\d+ I would like to change it to something like /A/B/C/D/E/F/filename_song-3.mp3 song is just a ...
2
votes
2answers
83 views

Filtering a file on a string

I have a file which looks like this a 0 gene1 56 0 6S32M12S * b 256 gene2 56 0 6S32M12S * c 256 gene3 55 0 6S27M17S * d 16 gene4 110 9 19S25M6S * e 272 ...
0
votes
1answer
27 views

putting headers back after awk command

I have file like this. Its called a sam file @HD VN:1.0 SO:unsorted @SQ SN:RNU2-1 LN:388 @SQ SN:RNU6-1100P LN:304 SRR959756.23 0 RNU2-1 56 0 6S32M12S * 0 0 ...
1
vote
2answers
65 views

How to make a filter more efficient

I've created a script to compare a list of users from a MSSQL database against a list of disabled AD users. The tool we use for AD authentication returns data in the following format (with plenty ...
1
vote
1answer
66 views

awk in ssh in su in a command substitution

I am creating a script that will ssh to a host and print all the user accounts and when they will expire. On a host I can run awk -F':' '{ print $1}' /etc/passwd and it will give me a list of all ...
1
vote
1answer
53 views

Get file names in awk result

I have many files in a location where I need to list file names in which 32th column has value more than 3000. This is the command that gives me those records: awk -F, '$32 > 3000' * Now can ...
3
votes
1answer
95 views

awk causing memory leak?

I am using awk to process a huge data file (about 100 million lines). This is my expression- tac <myfile> | awk -F',' 'OFS=\",\" ...
2
votes
1answer
111 views

Merge some tab-delimited files

I have 100 files with 57,816 rows each.I want to do an outer join of these files by merging on basis of the common column. I am using R programming for this but this is very slow. fileList <- ...
4
votes
5answers
9k views

removing the first and the last character of every line from command line

I am trying to remove the first and the last characters of everyline in a text file and save the resulting truncated version in a new file. Does anyone have an idea about how to do that efficiently ...
3
votes
4answers
154 views

pattern match and capturing in unix

I have a file like this: A1-1915435_1_MIMAT0000069_MirBase_miR-16_microRNA_1_22-A1-1915435_1_ENSG00000206737_ENST00000384010_U1_snRNA_73_115 ...
3
votes
3answers
110 views

Extract lines between and including 2 patterns

I have a file with data structured as follows 1, p1, p2, p3, p4, p5, p6, p7 2, p9, p10,, 2, q1, q2, q3, q4, q5, q6, q7 2, q9, q10,, 2, r1, r2, r3, r4, r5, r6, r7 2, r9, r10,, 1, s1, s2, s3, s4, s5, ...
1
vote
1answer
28 views

Analysing nginx error log

I am looking for a way to the following. Here is one line from nginx's error log. 2014/12/29 21:17:57 [error] 30078#0: *311826 openat() ...
1
vote
2answers
54 views

Remove a line if regex exists only in 1st column of each line in a csv file

I have the following comma-delimited data (spaces used for visual clarity): 1 2014 23 2352 19.24 7.18 1 2014 23 2353 19.78 4.65 24 2014 23 2354 20.26 25.34 1 2014 23 2355 26.65 42.76 1 2014 23 ...