awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

-1
votes
1answer
37 views

How to remove duplicate rows using awk while splitting file

I'm using awk in a shell script so I can split a file according to the 5th column. The code below is similar to the one I'm using: awk -F';' 'NR==1{h=$0; next} !seen[$5]++{f="FILE_"$5".txt";print h ...
3
votes
1answer
202 views

Extract specific columns from text file

There is a text file, with aboot 10000+ lines, in the format: field1 field2 field3 field4 field5 ... fieldX It needs to be converted to look like: field1,field2,field4,field3,field5 to fieldX The ...
4
votes
3answers
151 views

Duplicating a string variable in awk

I would like to precede each line with a number saying how many slashes the line has got. awk '{ l=$0; gsub("[^/]","",l); print length(l),l }' This doesn't work bacause l=$0 seems to assign by ...
14
votes
7answers
24k views

Remove comma between the quotes only in a comma delimited file

I have a input file delimited with commas (,). There are some fields enclosed in double quotes that are having a comma in them. Here is the sample row 123,"ABC, DEV 23",345,534.202,NAME I need to ...
3
votes
1answer
30 views

awk not doing a new line

I'm trying to print out the users who are currently logged in (each logged in user of each terminal). This is what I currently have: NOWDATE=$(date +"%Y-%m-%d") NOWTIME=$(date +"%T") USERS=$(who | ...
1
vote
1answer
65 views

expand data based on scores

Firstly I have a set of valid combinations of 3 columns (validlist), so the final result must be a subset of this file. a b c c b c p b d d y d p y d x y z I have a score ...
1
vote
1answer
40 views

Match data from array to data from file?

I'm trying to match up the data from an array the lists the days of the week like this: MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY The files data reads like this: Name1,Tuesday ...
3
votes
1answer
87 views

sed: cut line X and append to top of the file

I would like to be able to cut line X and insert the line X on position y (top). This would help me to be able to reorganize some config files. Text example line number 1 <--- Append line 10 ...
2
votes
4answers
58 views

Remove partial duplicates consecutive lines but keep first and last

I have log files with a time stamp and six values in each line i want to reduce the amount of data, by removing consecutive lines with the same values (ignoring time stamps) and keeping the first and ...
2
votes
2answers
133 views

pipe ls and awk to rsync

Trying to complete a script with the following steps: (1) select 1gig of most recently changed files across a number of subdirectories (2) preferably uses rsync to copy the files to local directory -- ...
6
votes
2answers
3k views

Replace string with sequential index

Can someone suggest an elegant way to accomplish this? Input: test instant () test instant () ... test instant () //total 1000 lines output should be: test instant1 () test ...
2
votes
2answers
50 views

Combine columns using awk? (Or other suggestions)

I'm trying to be a bit effective and need a script or command solution. Say I make a file with 2 columns, or two files with one column, whichever is easier: AA1 B2 ZZ1 YYY XX1 AA2 B2 ...
1
vote
3answers
127 views

Match lines beginning with the same pattern in two text files

I am now having two text files with some of the lines beginning with the same pattern. For example, File A 1Mo 1,1 I love you. 1Mo 1,2 I like you. Hi 23,3 I am hungry. Hi 23,4 I am foolish. File ...
3
votes
4answers
238 views

How to get Disk space(Avail) using 'df -h' when Filesystem is long

I am trying to find available disk space through console I found df -h | awk '$NF == "/" { print $4 }' to get required output. [root@tmpe2etstmsdc01 ~]# df -h Filesystem ...
2
votes
2answers
70 views

Trying to convert a simple C program into an AWK program

Hey guys a couple of weeks ago I wrote a C program that prompts the user for the name of a text file and then prompts the user for a word. The program then outputs the input text file with numbers to ...
3
votes
2answers
48 views

Averaging and moving a selection of files

I have a bunch of directories, each of them enclosing an ascii table named accordingly with the directory name; as follow: a1/a1.txt a2/a2.txt a3/a3.txt a4/a4.txt b1/b1.txt b2/b2.txt b3/b3.txt ...
4
votes
5answers
91 views

Count unique associated values in awk (or perl)

I've already found "How to print incremental count of occurrences of unique values in column 1", which is similar to my question, but the answer isn't sufficient for my purposes. First let me just ...
4
votes
3answers
6k views

How to add Multiple Searches in AWK command

Im trying to search for the files Created in June,July and August months. I used this method ls -lrth|awk '/[Jun][Jul][Aug]/ {print}' but it ain't working. Please help me correct the syntax.
1
vote
2answers
136 views

Using awk and grep for iftop results

I wanted to monitor my server network send and receive rate using iftop. This is what works for me: iftop -t -s 1 -n -N | grep 'Total send and receive rate: ' | awk '{print $8}' Mac address and Ips ...
1
vote
1answer
66 views

How do I keep awk variables in scope?

I am attempting to keep track of the lowest/highest values from a list of counties and populations. I can't figure out how to stop variables from resetting themselves at 0. This is my cmd.awk ...
5
votes
1answer
205 views

Sort output of awk except for first line?

This is a use case I am continually running into in parsing CSV files. When it is an inline awk script embedded in a shell script, I can use this workaround: myfile=$(mktemp) awk '(awk script here)' ...
1
vote
1answer
68 views

Nesting Awk and variable comparison [duplicate]

I found myself having to learn a bit of awk, and it's really cool, but I have a small problem I am facing. I have a script that has an output that is designed to be piped. Let's call it matrix. I ...
1
vote
2answers
274 views

How to call bash function from within awk?

This is a bit tricky; I'm trying to work out the best approach to this problem. I have a couple of approaches, but they seem really hacky and I'd like something a little more elegant. I want to ...
2
votes
3answers
77 views

How can I use (sed|awk) to mask an e-mail address with asterisks like <j******e@g***.com>

How can I mask a list of e-mail addresses like: John Doe <john.doe@gmail.com> John Doe <johndoe@hotmail.net> Jane Doe <j.doe@outlook.org> ... with sed (or awk) into something ...
1
vote
1answer
51 views

awk is not producing the desired output

Below is my command output. When I process it through awk, it is giving unwanted output. What am I doing wrong? # lvdisplay -m --- Logical volume --- LV Name ...
2
votes
1answer
45 views

Exclude similar values from awk

Kindly consider below files: File 1: boo,194,2322 foo,999,7559 File 2: boo,2322 boo,4526 foo,4222 foo,4223 I need to link Field1 in File 1 with Field1 in File 2 and get the related Field2 ...
1
vote
0answers
28 views

Selecting the columns from source file based on control file [duplicate]

I have requirement where I need to construct a file based on control file. The first row of my source file contains column names. The control file contains the columns which I need to output into a ...
2
votes
1answer
55 views

How to enter a sum derived from awk in the middle of text output [closed]

I am trying to print a sum in the middle of a line. My script prompts for a user name and then pulls a total number of processes and a total of time for that user from a file. I want to print a ...
2
votes
3answers
3k views

Awk: match exact string in line

I have this file a deiauk Biking US 200 G b kespaul 202 A c deiauk NY 222 5 Z And I want to match the exact string 200 using awk. So my result should be a deiauk Biking US 200 G Here's my code ...
2
votes
3answers
3k views

Using awk to sum the values of a column, based on the values of another column

I am trying to sum certain numbers in a column using awk. I would like to sum just column 3 of the "smiths" to get a total of 212. I can sum the whole column using awk but not just the "smiths". I ...
4
votes
3answers
168 views

Concatenate several files with a common header

I have several text files, and each file's content is like attribute1,attribute2,... 1,2,... The first lines which describe the names of the columns are the same in all the files. I want to ...
3
votes
4answers
124 views

Split columns based on patterns in fields

Example: I'd like to split $2 in input file, putting a tab after pattern surname Input: name surname1 name surname30000 name surname456 Desired output: name surname 1 name ...
1
vote
1answer
48 views

Use awk to count number of /bin/false entries in a file in field7 with a single command for total count

I am having trouble using awk to count the number of /bin/false entries in a file in field7 with a single command. I can use grep no problem. I can use awk to count a few different ways. I have ...
0
votes
1answer
84 views

jumbled character set

In my Linux env, for some unknown! reason when I process a raw unformatted file which I copied from Win7prof (was encoded in utf-16), the resulting file is all jumbled. It will print OK in Linux ...
1
vote
0answers
34 views

tab-delimiting a file in shell

I have a file that I want to put in a table in SQL with 10 columns. I am trying to tab-delimit the file so that the file can go in the table. Here is part of my txt file: Chr12 MSU_osa1r7 exon ...
-1
votes
2answers
159 views

find and print file path, without filename

Please check the below awk '/SOURCE/ {print $3}' /MAC/Delete_Name.txt | while IFS= read -r file; do find /OS/ -iname "$file.pdf" ; done This results in output like this: ...
4
votes
1answer
2k views

Pass colors from ls through pipe to awk 'print' statement

This is a follow-up to my question from yesterday, Show sum of file sizes in directory listing. Thanks to Zero Piraeus and a point in the right direction by Mauritz Hansen, I now have function ...
3
votes
1answer
44 views

AWK sum column in file specify as a argument

I want to write a script that sums up my column in the file. The numbers of columns he wants to give as an argument. It may be several. I do not know how to solve this with awk so that sums up several ...
14
votes
3answers
68k views

How to run grep on a single column?

I want to grep the output of my ls -l command: -rw-r--r-- 1 root root 1866 Feb 14 07:47 rahmu.file -rw-r--r-- 1 rahmu user 95653 Feb 14 07:47 foo.file -rw-r--r-- 1 rahmu user ...
14
votes
9answers
32k views

How to print only last column?

echo -e 'one two three\nfour five six\nseven eight nine' one two three four five six seven eight nine how can I do some "MAGIC" do get this output?: three six nine UPDATE: I don't need it in this ...
-3
votes
2answers
28 views

AWK count how many instance after pattern match

For example: RXOTG-1388 holds 3 object RM4FD1,RM4FD2,RM4FD3 RXOTG-1398 holds 3 object VT08D1 VT08D2,VT08D3 and so on. Based on this text file I would like to count, using awk, how many object ...
10
votes
3answers
8k views

Diff, show modified line from right file only

I have file a and b and I would like to output lines of b that changed since it was cloned from a. Just the modified lines, no surrounding context, no diff offset marks. How can I do that using shell ...
2
votes
1answer
76 views

Using sed / awk to change words between two patterns

I'm writting the shell script that should process through some text, I've got the text like that: read build { file1 file2 file3 } check build { file2 file3 file4 } read build { file4 file5 file6 } ...
2
votes
1answer
28 views

Help with averaging specific columns awk

I need to process some data for my dissertation and I need to do it though Linux as I have > 2 million points. I've currently gotten my selected data it in a file that looks something like this using ...
1
vote
1answer
52 views

Combine range of columns with the same key

Input file tab separated: A |B | C | KEY | D| E| F |G | H | I | J | k | ----|----|----|------|---|---|-----|------|---|---|-----|-----| word|word|word| one | 8| ...
-1
votes
2answers
32 views

putting output into sql table

I am trying to convert the output of ps awux into 11 fields with the headers eliminated and then importing that output into an existing table in SQL.
2
votes
2answers
72 views

Replacing matching text after two matching lines

I have a YAML file which includes a stanza looks this: admin::common::passwords: alice: password: '$6$oTQhLvN/4VFJPscD$8LYwUMSFi' bob: password: '$6$JKOtLF0wHeZfIskt$W/M5.ugDS' If the ...
1
vote
3answers
421 views

How to extract XML from a text file

I have a text file as below. 1001=<?xml ns=dkfj><home><taga>dkjf</taga></home>1002=<?xml ns=dkfj><home1><taga>dkjf</taga></home1> I need ...
1
vote
3answers
61 views

Compare two files column values using awk

Here is the content of two files : Judi # cat File1 judi /export/home 76 judi /usr 83 judi # cat File2 judi /export/home 79 judi /usr 82 If column 3 of File2 is greater that column 3 ...
0
votes
1answer
126 views

print column value based on column name match in awk/sed [duplicate]

In my shell script after executing a few commands, I'm getting the output below: Name English Maths science Social studies ------ -------- -------- -------- --------------- James ...