awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

3
votes
2answers
133 views

Join: Two files - but only append last two columns

Given the files: 1.txt 1, abc, 123, 456, 789 2, lmn, 123, 456, 789 3, pqr, 123, 456, 789 2.txt 1, abc, 123, 000, 000 3, lmn, 123, 000, 000 9, opq, 123, 000, 000 OUTPUT.txt ID, NAME, X, ...
3
votes
3answers
125 views

Join every other column with sed or awk

I have a large text file (666000 colums) in the format A B C D E F Desired output AB CD EF How can we do it in sed or awk. I have tried a couple of things but nothing seems to be working. Please ...
6
votes
5answers
221 views

Get filesystem name and usage with `df -h`

df -h | grep test | sed -e 's/*%.^ //g;s/.*[ ^I]//' Output: /test /test/drv0 /test/drv1 df -h | grep test | cut -d '%' -f1 | sed -e 's/*%.^ //g;s/.*[ ^I]//' Output: 10 20 15 I want to ...
2
votes
1answer
75 views

Regular Expressions within a string in AWK using if/then control structure?

PROBLEM I want to specifically use AWK (GAWK, MAWK, whatever) in an AWK script to sum up the values in field 9 for every record that contains "runner__.jpx" (the underscores are placeholders for two ...
2
votes
3answers
555 views

Comparing files line by line in awk with delimiter

file1: abc|123|check def|456|map ijk|789|globe lmn|101112|equator file2: abc|123|check def|456|map ijk|789|equator lmn|101112|globe EXPECTED OUTPUT: ijk|789|equator lmn|101112|globe Current ...
2
votes
4answers
135 views

AWK Search massive file and write to variable name

I want to pull data that I will need to reformat from a simulation file I am working with to prepare it as input for running other simulations. The target data is an optimized chemical z-matrix. The ...
1
vote
2answers
60 views

How can I reformat tabular data using AWK?

I have a file contain following output. ora.abc.db 1 ONLINE ONLINE serverA Open 2 ONLINE ONLINE serverB Open ora.xyz.db 1 ...
1
vote
1answer
445 views

How to find out the content of a XML file using Unix Sed/Awk? [duplicate]

I have a XML file(MyXML.xml) like this : <?xml version="1.0" encoding="UTF-8"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> ...
2
votes
4answers
81 views

Alternative regex for {}

I am trying to replace all of this line, but the numbers: looktype="123" so only the numbers show up. Is this possible in any easy way? {sub ("look type=\"[0-9]{0,3}", "TEST")} I am trying this ...
0
votes
1answer
82 views

how to assign values of the column for given conditional statements

I need help with a script to assign values of the column with a given conditional argument. To be specific, here is my data and my condition input data.file: 0.4 3.6 -2.4 0.1 -2.0 1.6 2.2 3.6 ...
6
votes
4answers
496 views

uniq a csv file ignoring a column, awk maybe?

Given this file (annotations are not part of file, but form part of explanation)... x,a,001,b,c,d,y x,a,002,b,c,e,yy x,bb,003,b,d,e,y x,c,004,b,d,e,y x,c,005,b,d,e,y # nb - dupe of row 4 ...
1
vote
1answer
82 views

doubt regarding use of split in awk

arr=($(echo "great#man" | awk '{split($0,a,"#"); } END {print a[0]; print a[1];}')) echo " ${arr[0]} " echo " ${arr[1]}" My expected output is: great man But I am getting great ...
4
votes
3answers
750 views

Summing up an array inside of awk?

I have the following piece of code: sum1= sum2= declare -a a echo $temp | awk '{split($0,a,","); name=a[1] ; for(i=2;i<=4;i++) sum1+=a[i] ; for(i=5;i<=7;i++) sum2+=a[i] }' This code is ...
9
votes
2answers
607 views

Script to quickly test all keyboard keys

I need to check some notebooks for bad keyboard keys, and so I'd like to speed that up as much as possible. I found nothing for this specific task, so my idea is a script that reads the pressed keys ...
2
votes
3answers
173 views

How does this awk align the spacing?

Can someone please tell me what does this do? cat infile| awk ' { for(i=3;i<=NF;i++){ $2=$2" "$i } printf "%-4s %s\n", $1,$2 ; }' > outfile.txt infile contains: 1 John Smith 2 ...
4
votes
4answers
230 views

Joining two files with unique identifier

I have two files with approximately 12900 and 4400 entries respectively, that I want to join. The files contain location information for all landbased weather observing stations around the globe. The ...
1
vote
4answers
800 views

How to extract line from the file on specific condition

File: chromosome position ref alt chr1 1398 A T chr1 2980 A C chr2 3323 C T,A chr2 3749 T G chr3 5251 C T,G chr3 ...
2
votes
2answers
394 views

How to remove an apostrophe ( ' ) from couple of columns of a .CSV file?

I have a .CSV file with 7 fields, and the 3rd and 4th columns of the file has a number starting with an apostrophe ( ' ). Please see the example below. col0,col1,col2,col3,col4,col5,col6, ...
1
vote
2answers
2k views

How to select, copy and paste some columns from different files and create one file from them?

I want to create and organize data in a file from a number of files by selecting parts of the columns of the given files. I have more than 10 file to copy the second, third and forth columns of each ...
2
votes
3answers
92 views

How to run awk for some number of lines.?

I want to extract some lines with awk. Is it possible to do the following task: ls -l | awk 'BEGIN FOR(i=122;i<=129;i++) FNR==i' How can I display the details from line numbers 122 to 129?
1
vote
3answers
1k views

How to convert from one date format to other format?

I have one problem with my date format. I want to change from one format to the other and vice versa. My date formats are Format 1 YYYY-MM-DD Format 2 MM/DD/YYYY I want to change format 1 to ...
4
votes
6answers
96 views

Only show the lines that are in all textfiles at least once

a.txt cat a.txt a b x c b.txt cat b.txt d e a f the q: SOMEMAGICK *.txt a Q: how can I show only the lines that are in all *.txt files?
1
vote
3answers
148 views

how to calculate the average value of the column that have the row ID?

I want to calculate the average value of my data when they have the same ID (in my specific case, the same day but different time in a day). This is meant to calculate the daily average value of my ...
1
vote
1answer
50 views

how to clean free row/column spaces after the row of your data

I have a problem in cleaning my file where there are unnecessary free spaces below my last data row. This is created when I am copying and pasting my data from excel to text. I want my text file to ...
1
vote
2answers
67 views

how to select part of the row and pasting to form other file?

I want you help me how to organize my data by cutting in the following way. I have the input data as below. input.file: 1 2 1 0.6007 0.1 0.3 0.2 0.7 0.7 0 2 0.3073 0.1 0.1 0.2 0.4 0.7 ...
0
votes
4answers
985 views

Match multiple regular expressions from a single file using awk

I'm trying to parse a HTML file using shell scripting. There are 4 different regular expressions that i need to catch: name= , age= , classs= , marks=. Using grep "name=\|age=\|class=\|marks=" ...
2
votes
3answers
138 views

how to create a data file with a column of date from day1 to dayN?

I was wondering if I could generate a hourly or daily time step date in a column starting from some year in the past to some day in the near past or today. to be more clear, I want to create one ...
10
votes
5answers
958 views

Using grep or awk

To capture a particular pattern, awk and grep can be used. Why should we use one over the other. How does this work in the background? Which is faster and why? E.g If I had a log file and I wanted ...
2
votes
3answers
220 views

sed - find string and append

Suppose you have the following text file 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 ...
1
vote
4answers
1k views

Finding out the common lines in two files using 4 fields using awk and UNIX

I have 2 files. If field 1, 2, 4 and 5 of both file1 and file2 matches, then I want to print the whole line of file1 and file2 one after another in my output file. File1: sc2/80 20 . ...
3
votes
3answers
2k views

importing data from a text file to a bash script

I need to import a text file like this below: AMBI CBNK CCXI CERE CLACW CNYD DAEG DLIA DLLR DNDN DSGX HAST HIBB, HPOL IRDMZ MARK NEPT NFEC NINE NRCIB OMER PLCC PLPM PSUN UNTK There are 25 entries, ...
4
votes
1answer
102 views

Looking for lines which is in one file but not in other using Unix and Awk

I have 2 files with 7 fields and I want to print the lines which are present in file1 but not in file2 based on field1 and field2. Logic: I want to print all the lines, where there is a particular ...
0
votes
6answers
1k views

Using cut/awk/sed with two different delimiters

I have the following cases: case@test.com case_1_2@test.com case_1@test.com I'm trying to convert these to case@test.com case@test.com case@test.com So it should remove everything from ...
2
votes
4answers
389 views

Can awk use field identifiers also for shell strings (variables)?

Well, this apparently is not possible the way I'm trying it. This alternate approach to obtain bar as a resulting string works, though: #!/bin/bash path1=/usr/tmp/foo/bar/baz awk -F/ '{print $5}' ...
3
votes
3answers
114 views

Easily get a particular column from output without sed or awk

Is there a quicker way of getting a couple of column of values than futzing with sed and awk? For instance, if I have the output of ls -hal / and I want to just get the file and directory names and ...
2
votes
1answer
621 views

Comparing Files based on 5 fields using Awk and Bash

I want to compare File1 and File2 (Separated by spaces) using five fields (Column 1,2,4,5,6). *Logic:*If column 1 and 2 of File1 and File2 match exactly and if the File2 has the same characters as ...
1
vote
3answers
276 views

How to limit MAX an MIN length of a string?

"nothing" means no OUTPUT. Q: how can I limit the MIN and MAX length of a piped STRING? (MIN: x>=3 chars, MAX: x<=32 chars) INPUT: echo 12 | MAGIC OUTPUT: nothing INPUT: echo 123 | ...
1
vote
1answer
50 views

How to make URL's out of this text with least resources?

INPUT: nyeeeeeeeeeeeeeee.txt:sadfsadf sadjflsajfd:jasdlfjalsfd foo/asdfsafd.txt:laksjdlfajsfd OUTPUT: <a href="nyeeeeeeeeeeeeeee.txt">nyeeeeeeeeeeeeeee.txt</a>:sadfsadf <a ...
1
vote
1answer
111 views

Searching for all the array elements in another array?

This is how I would search for an element in an array. count=${#ARRAY[@]} lsearch() { status=-1 for((i=0;i<count;i++)) do Temp=$1 if [[ $Temp -eq ${ARRAY[i]} ]] then ...
1
vote
1answer
238 views

How to integrate a multiline awk script in a shell script

I am a beginner in shell scripting and my question is a continuation of How to parse a file to extract 3 digits numbers kept in a "group number" I am trying to integrate in a single shell ...
4
votes
1answer
179 views

grep: display filename once, then display context with line numbers

Our source code has error codes scattered throughout. Finding them is easy with grep, but I'd like a bash function find_code that I can execute (eg. find_code ####) which will provide output along ...
4
votes
1answer
566 views

Sorting a file based on one column using Unix and Awk

I need to sort the input file according the 6th column, which is the score. Input File: Sc2/80 20 . A T 86 Pass N=2 F=5;U=4 Sc2/80 20 . A C 80 Pass N=2 F=5;U=4 Sc2/60 55 . G T 90 Pass N=2 F=5;U=4 ...
2
votes
3answers
83 views

Pulling out keywords using standard command line utilities?

As an example, this is the pronunciation of "when" according to Wiktionary. enPR, IPA and X-SAMPA are different schemes for showing pronunciations. when:* {{a|US}} {{enPR|wĕn|hwĕn}}, ...
0
votes
1answer
67 views

Splitting Apache Vhosts into Individual Files

I have several vhosts in one file that I am looking to break each into a file of their own corresponding to the ServerName. I'm looking to take this file <VirtualHost *:80> ServerName ...
3
votes
2answers
684 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.
3
votes
7answers
781 views

Problem in splitting a string using awk or cut command

I have a properties file which has a password field (key value pair) PASSWORD=NDhhHcsOBofXUdUzGw5B0Q== I am trying to get the value in my shell script using the awk command password=`awk -F "=" ...
2
votes
2answers
984 views

Comparing two files using Unix and Awk

I need to compare two files, File1 and File2 (Separated by space) using 4 fields (Field 1, 2, 4 and 5 of File 1 with field1, 2, 4 and 5 of File2). Logic: If column 1, 2 and 4 of File 1 matches with ...
2
votes
6answers
149 views

Bash - Split the previous commands parameters

How would one parse the previous command in bash? Example: root$ ssh foo@1.2.3.4 root$ echo !$ &>/tmp/foo.txt root$ cat /tmp/foo.txt foo@1.2.3.4 Goal: Send just the ipaddress 1.2.3.4 to ...
1
vote
3answers
130 views

Cat 2 files and avoid duplication of lines

I have the file1 with the following content {"name":"clio5", "value":"13"} {"name":"citroen_c4", "value":"23"} {"name":"citroen_c3", "value":"12"} {"name":"golf4", "value":"16"} {"name":"golf3", ...
1
vote
1answer
58 views

How to design the table in awk?

My input file is file1 count month 505 Apr-2010 252 Mar-2010 426 Feb-2010 201 Jan-2010 211 Dec-2009 Same file I want the output like this below +-------+----------+ | count | month ...