awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

0
votes
1answer
21 views

Changing file name from dbf to ods problem?

I was trying to change the file name from gdf to csv in the folder using $for i in *.dbf; do mv $i ${i%.dbf}.ods; done script. The code changed all the gdf to csv, but the content of the new ...
1
vote
1answer
19 views

awk: Columns are not printed when concatenating strings is passed as command string

I've found some anomaly when writing a script. The following examples works as expected: $ echo 123 | awk '{print $1 456}' 123456 $ sh -c "echo 123 | awk '{print $1}'" 123 But the following ...
0
votes
1answer
31 views

How to copy rows of different files and paste column-wise?

I want to create a new file by copying rows of each file and pasting columnwise according to their file name orders. Here is the sample input and required output files below. file1.txt 1234 5678 ...
-2
votes
2answers
37 views

Unix AWK command with multiple field seperators [on hold]

I faced a problem with awk where my field separator has multiple characters. I have found the solution but I am unable to understand the script. awk 'BEGIN{FS="[char1][char2][char3]+";} This is how ...
1
vote
1answer
43 views

awk: for-loop with break option

I am trying to use awk to manipulate data.I have a data file with two columns and I would like to find the row that contains an specific value. But there is more than one row that contains this value ...
1
vote
2answers
49 views

grep contents of files based on a list of files

Running CentOS 6.5, qemu-kvm. I have a script which builds a list of running VM's. I want to pull information from those .xml files of only the VM's that are running. cat /dev/null > ...
1
vote
3answers
23 views

Concatenate Sequences under a Heading

I have a file like File1. With a heading for example ">Contig1" and I want to concatenate all the sequences under the respective heading. File1: >Contig1 ACCCCATACATCCAAA NNNNNNNNNNCATACA ...
0
votes
2answers
40 views

joining 2 files on 2 columns but at different column numbers using awk

I have 2 files which has to be joined on $1,$2 of 1st file and $1,$8 of 2nd file using awk.Can anyone please provide the solution for this as this is an urgent requirement. Thanks in Advance file1: ...
1
vote
2answers
35 views

Passing print pattern as a variable to awk

I am trying to use awk to print variables from various columns in a line delimited by , .The columns and pattern which I want to print is stored in another variable b. The pattern a and print patter ...
0
votes
5answers
69 views

print only rows that has latest non empty cell that starts with the word “Failed” on a CSV file in Linux [on hold]

I want to print the table only if non-empty latest column that starts with the word "Failed"on a CSV file in Linux.. My input - Name,Mon,Tue,Wed,Thu,Fri,Mon Linux,Successfull Fullbackup; Failed ...
3
votes
3answers
47 views

Removal of lines with more than 'N' fields?

I am working on mac with sed, perl, awk, bash.. I have a large-ish (10GB) text file which has 13 fields (columns) of TAB delimited data. Unfortunately some of these lines have extraneous TABs , so I ...
0
votes
1answer
26 views

How to print 1st and 4th variable only if 4th variable is > or equal to 25

Networking: [Test] => 10.729519791085 GAMES: [Real] => 10 Fashion: [Test] => 27.729519791085 Movies: [Real] => 5 Food: [Test] ...
3
votes
3answers
78 views

Remove duplicate fields in a given column

I'd like to remove from a given column ($2 in the example) the duplicate fields (comma separated). Input file: A 1,2,3,4 B 4,5,6,3 C 2,15 Expected output: A 1,2,3,4 B 5,6 C ...
3
votes
4answers
171 views

Count how many elements in the nth column in a whole file

Input file: A 1,2,3,4 #length($2)=4 B 1,2 #length($2)=2 C 9,8,7,6,5,4 #length($2)=6 Expected output: 12 #4+2+6 A method like: awk -F '[\t,]' '{print length($2)}' but ...
-4
votes
0answers
36 views

Can you please explain this syntax for me [closed]

Please can you explain this syntax $ awk 'BEGIN{FS="FS";}'
3
votes
3answers
118 views

Parse multiple sections of data into seperate files

I have a concatenated log file with multiple logs inside that I'm trying to parse out into individual log files (I will later rename them to the date/time of each). Each log is separated by "--- LOG ...
2
votes
2answers
32 views

Delete rows in a csv file based on a specific column value

I have a csv file with the following headers - Interaction_ID, PDB_ID, First_Residue, First_Chain, Second_Residue, Third_Residue, Third_Chain & Pattern: ...
3
votes
4answers
69 views

How to remove text matching specific patterns from a file

I want to compare two files to check for differences between them, fileA and fileB. fileA is like a template file and fileB is the file which I want to compare to it. Anytime I find a difference I ...
1
vote
3answers
39 views

Trouble in adding a column with awk

I'm trying to add a column to a csv file by using: awk -F "," '{print $0"new_col"}' file.csv but I got : new_col8,0.405,0.101 new_col4,0.374,0.100 new_col23,0.342,0.100 new_col130,0.298,0.100 ...
0
votes
3answers
41 views

Replace specific text only in specific fields using nawk

My input data file abc.txt has this "20131008","0004","0568","98" I ran this command to replace the text nawk -F, -vOFS=',' '{gsub("0568","0808",$3); print }' abc.txt In the output the ...
4
votes
3answers
115 views

find length of longest line in all text files in a directory

I know how to get length of the longest line in a text file with awk awk ' { if ( length > L ) { L=length} }END{ print L}' file.txt but how can I get the length of the longest line of all files ...
5
votes
4answers
210 views

How to replace all the first occurences in matched lines with incremental number?

I have a file like this ... 1562 first part 1563 H col3 H col4 1564 H col3 H col4 ... 3241 H col3 H col4 3242 third part ... I want to replace only the first H in every line to H#, with ...
2
votes
1answer
23 views

Get each column which contains multiple spaces?

My file: subnet 172.25.10.0 netmask 255.255.255.0 { option domain-name-servers 172.25.10.9, 8.8.8.8; default-lease-time 300; max-lease-time 7500; range dynamic-bootp 172.25.10.10 172.25.10.30 ; ...
3
votes
6answers
216 views

Convert string into date time stamp in gawk or awk

I want to convert following string (20140805234656) into date time stamp (2014-08-05 23:46:56).I am new to gawk and I don't know the exact syntax,how can I put - at every 5,8 and : at every 14,17 and ...
4
votes
6answers
285 views

want the last line when duplicate awk?

I have the file: key value blah blah blah blah blahblah man1 boy1 blah blah man1 boy2 man1 boy1 I do this to remove duplicate lines: awk '/man1/ { print $1,$2} ' file | awk '!x[$0]++' and the ...
3
votes
1answer
41 views

Handling dynamically changing column positions and splitting file

I have a unique problem. I have a file with following columns PersonId, AB1, AB2, AB3, DG1_B1,DG1_B2,DG2 1,0,1,0,3,5,7 2,0,3,1,3,7,4 I want to split this and create multiple files based on the ...
0
votes
5answers
49 views

re-arrange values in one column without affecting other columns using awk or sed

I have a csv file in following format: abc,124,123,2014-08-13,abc def,124,123,2014-08-13,abc ghi,124,123,2014-08-13,abc Now I need to modify only 5th column (2014-08-13) to produce output as given ...
2
votes
1answer
27 views

Move matched line above a different matched line using sed

I have something like dsadjakldjska safdsfdsfsf fdsfsf**STGN**fdsfsd fdsfkjldsf fdsff fdsfs**IRV**fdsfs and I want to get dsadjakldjska safdsfdsfsf fdsfkjldsf fdsff fdsfsf**STGN**fdsfsd ...
2
votes
2answers
42 views

Memory allocation for sparse array in awk

I have searched but didnt reach to any conclusion that when i defined an sparse array does it reserve all the contiguous memory upto maximum index or it allocate the memory at that particular index ...
2
votes
4answers
74 views

Insert new line after non matching pattern

I have following output from script host1:101 host1:102 host2:101 host2:102 host2:103 host4:101 host5:101 host5:102 host5:103 host5:104 etc.. I wanted to insert a new line after each host group. ...
2
votes
6answers
424 views

Handling comma in string values in a CSV file [duplicate]

I have a comma-separated file which has numeric and string columns. String columns are quoted and can have comma in between the quotes. How do I identify the columns with FS =","? Sample records ...
4
votes
3answers
342 views

pipe line with non-deterministic output

I have happened upon a command that sometimes works and sometimes does not, even when executed multiple times in rapid succession in a bash shell (I have not tested the behavior in other shells). The ...
0
votes
2answers
100 views

Delete every number that comes before “=”

i have a very, very, very long list. Like over 830,000 characters. I will of course perform said command on a copy. There are multiple lines, like this hey1=lol hey2=lol hey3=lol I want that to ...
1
vote
2answers
29 views

cygwin awk output to windows line delimeters

I could find the way to print zip entries' list and forward to a txt file. unzip -l my.zip | awk '{print $4}' > my.txt When I open the file my.txt in windows' notepad the line delimiters ignored ...
5
votes
3answers
521 views

How to understand the command awk '{for(x=1;$x;++x)print $x}'?

I know this command awk '{for(x=1;$x;++x)print $x}' will print out all columns in a line. wouldn't this ++x change x to 2, and thus print $2 first? As I understood based on this: ...
2
votes
2answers
160 views

awk character class mystery

I seem to be unable to use a character class for an awk regular expression, almost exactly as described here : user@host:~$ awk -W version mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan ...
-3
votes
2answers
55 views

Extract certain column from CSV files [closed]

I have a directory with a group of CSV files. All files have the same column headers. I need to extract values in a certain column from all files. The common part in files names is ...
0
votes
2answers
114 views

Rearrange the file content

I have a file with content as 123 OneTwoThree 234 TwoThreeFour 345 ThreeFourFive I want to convert this file into something like this OneTwoThree 123 TwoThreeFour 234 ThreeFourFive 345 Here ...
5
votes
6answers
196 views

Remove duplicates values within a field

How to remove duplicate (or more) values within a selected field in a file, keeping only one copy? Exemple Input file: A 1,2,3,45,1,8,2,3 B 5,6,6,6,6,6,2,3,7 Expected output: A ...
2
votes
2answers
52 views

How to escape spaces etc in passed variable, for system call to cp in awk

As the title suggests, this problem has enough layers of complexity to make simple escaping characters difficult for me. I have a bash script which, for a large part, has an embedded awk script that ...
0
votes
3answers
53 views

awk pattern matching and merge files

I have 3 files 1.csv and 2.csv and 3.csv 1.csv TELECOM_DEVELOPMENT_AFGHANISTAN_COMPANY,AFGHANISTAN,Alphanumeric_A_MSISDN_blocking,1 ...
2
votes
5answers
158 views

extracting/copy ranges of columns from large data file

I was trying to prepare data files from one large file by extracting columns and pasting into a new file. The number of columns of the given data is very large. I want to prepare a number of data ...
1
vote
2answers
36 views

awk - read program AND input from the standard input?

Is it possible for awk to read the program and the input from the standard input? I would like to be able to pipe a file to the following function. process_data () { awk -f - <<EOF {print} ...
5
votes
4answers
207 views

How to replace m part of Lines with n part of Lines?

I have a file "test" like this: RewiteEngine On RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.7$ [NC] RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.8$ [NC] RewriteCond %{REMOTE_ADDR} ...
0
votes
4answers
62 views

Extract value between double quotes

My query is to extract the value between double quotes "". Sample input is : 10.219.41.68 - - - [11/Jun/2014:10:23:04 -0400] Sec:0 MicSec:1797 "GET /balancer-manager HTTP/1.1" 200 28980 "-" ...
1
vote
2answers
102 views

Extracting text string from file, assigning them to variables then writing them to another file?

Basically, its a game server (minecraft) and I have a situation where I am attempting to automate new world generation. Basically, I have a file that gets generated happily which has this snippet in ...
5
votes
1answer
78 views

Delete an array in awk

In awk, I can clear an array with a loop, making it an empty array, which is equivalent to deleting it. for (key in array) delete array[key]; Is there a simpler way? Can I completely delete an ...
3
votes
1answer
49 views

grep upto matching brackets

I have a file like this:- pin(ABC) { a b c d e f { abc } } pin(XYZ) { g h i j k { j k { ...
-2
votes
0answers
22 views

remove duplicates from file1 if entry present in file2 [duplicate]

Input file1: x1 y1 x2 y2 x3 y3 x4 y4 y1 x1 x5 y5 y3 x3 x6 y6 x5 y5 Input file2: y1 x1 y2 x2 y3 x3 y4 x4 x1 y1 y5 x5 x3 y3 y6 x6 x5 y5 Desired output: x1 y1 x2 y2 x3 y3 x4 ...
0
votes
2answers
43 views

remove duplicate entry from file1 if entry present in file2

I want to delete duplicate entry e from file1 if e is also present in file2. Input file1: x1 y1 x2 y2 x3 y3 x4 y4 y1 x1 x5 y5 y3 x3 x6 y6 x5 y5 Input file2: y1 x1 y2 x2 y3 x3 y4 x4 ...