10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I need to print field and the next one if field matches 'patternA' and also print 'patternB' fields.
echo "some output" | awk '{for(i=1;i<=NF;i++){if($i ~ /patternA/){print $i, $(i+1)}elif($i ~ /patternB/){print $i}}}'
This code returnes me 'syntax error'. Pls advise how to do properly. (2 Replies)
Discussion started by: urello
2 Replies
2. UNIX for Beginners Questions & Answers
Hi, I have two TEST files t.xyz and a.xyz which have three columns each. a.xyz have more rows than t.xyz. I will like to output rows at which $1 and $2 of t.xyz match $1 and $2 of a.xyz. Total number of output rows should be equal to that of t.xyz.
It works fine, but when I apply it to large... (6 Replies)
Discussion started by: geomarine
6 Replies
3. Shell Programming and Scripting
In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies
4. Shell Programming and Scripting
I am trying to use awk to match the NM_ in file with $1 of id which is tab-delimited. The NM_ will always be in the line of file that starts with > and be after the second _. When there is a match between each NM_ and id, then the value of $2 in id is substituted or used to update the NM_. Each NM_... (3 Replies)
Discussion started by: cmccabe
3 Replies
5. UNIX for Beginners Questions & Answers
I'm trying to use awk to count the occurrences of two matching fields of a CSV file.
For instance, for data that looks like this...
Joe,Blue,Yes,No,High
Mike,Blue,Yes,Yes,Low
Joe,Red,No,No,Low
Joe,Red,Yes,Yes,Low
I've been trying to use code like this...
countvar=`awk ' $2~/$color/... (4 Replies)
Discussion started by: nmoore2843
4 Replies
6. Shell Programming and Scripting
Trying to combine strings that are a partial match to another in $1 (usually below it). If a match is found than the $2 value is added to the $2 value of the match and the $3 value is added to the $3 value of the match. I am not sure how to do this and need some expert help. Thank you :).
file
... (2 Replies)
Discussion started by: cmccabe
2 Replies
7. Shell Programming and Scripting
Trying to use perl to output specific fields from all text files in a directory to one new file. Each text file on a new line. The below seems to work for one text file but not more. Thank you :).
perl -ne 's/^#//; @n = (6, 7, 8, 16); print if $. ~~ @n' *.txt > out.txt
format of all text... (2 Replies)
Discussion started by: cmccabe
2 Replies
8. Shell Programming and Scripting
Hi,
i am trying to count the fields in a file.
Input:
100,1000,,2000,3000,10/26/2012 12:12:30
200,3000,,1000,01/28/2012 17:12:30
300,5000,,5000,7000,09/06/2012 16:12:30
output:
Cout of the fileds for each row
6
5
6
awk -F"," '{print $NF}' file1.txt
When i try with above awk... (3 Replies)
Discussion started by: onesuri
3 Replies
9. Shell Programming and Scripting
I need to take 2 input files and create 1 output based on matches from each file. I am looking to match field #1 in both files (Userid) and create an output file that will be a combination of fields from
both file1 and file2 if there are any differences in the fields 2,3,4,5,or 6.
Below is an... (5 Replies)
Discussion started by: ambroze
5 Replies
10. Shell Programming and Scripting
Hello All,
I got a requirement when I was working with a file. Say the file has unloads of data from a table in the form
1|121|asda|434|thesi|2012|05|24|
1|343|unit|09|best|2012|11|5|
I was put into a scenario where I need the field count in all the lines in that file. It was simply... (6 Replies)
Discussion started by: PikK45
6 Replies