awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

-1
votes
2answers
1k views

How can I print unique line base on particular column value using awk? [closed]

I have a comma separated file with multiple fields. Example: candidate1,12,56,ATTG candidate2,45,90,ATTG candidate3,90,140,ATTG candidate4,2,36,AGCT So, does anyone know the answer?
0
votes
4answers
3k 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 ...
1
vote
2answers
502 views

Use FOR Loop inside END block of awk command

I'm trying to find the average number of files per day. The following script works: #!/bin/sh ls -l | grep "^-" | awk '{ key=$6$7 freq[key]++ } END { for (date in freq) printf ...
4
votes
3answers
731 views

Change the text on a single line number in multiple text files

Suppose that I have ten bash shell scripts: script1.sh, script2.sh, ..., script10.sh. Initially, all ten files are identical. Now, I would like to make two changes in each script: In each file, ...
1
vote
1answer
259 views

awk can't print array element

Lets sat my file1 is: A S B Q file2 is: B 2 I want to match $1 from file2 with $1 file1 and print file1 $2 && file2 $2, for the output like this: Q 2 My awk solution ...
2
votes
2answers
79 views

Print line n-1 (and n) if line n fulfills condition

I have a fasta file looking something like this: >19 dna:chromosome chromosome:NCBIM37:19:1:61342430:1 37330562 ID13406 U - TACATGGGTGACAAGGAGGTCAGGTGTTA >19 dna:chromosome ...
5
votes
1answer
1k views

Removing leading zeros from DATE

I made an alias of the date command to display date in the following format: 2013.06.14.12.10.02 using this command: alias date = date +"%Y.%m.%d.%H.%M.%S" Everything works great, except I ...
1
vote
2answers
87 views

Grep and sort several unsorted things in several lines (in one document)

I have a file with several unsorted things in one line which I want to put into a new file This is an example of part of the file I have: X1314448: SaMi|SM_g2554.t1 SaMi|SM_g5072.t1 Des|Des_g3808.t1 ...
4
votes
2answers
317 views

Use sed or awk to join lines in a certain pattern?

Not sure on how to turn this input: A B C apartner bpartner cpartner into this output: A apartner B bpartner c cpartner I have this pattern in a 80 line file that needs to be 40 line. Also, how ...
4
votes
2answers
171 views

AWK - a question about columns

I have a question. I was trying to deal with it by myself, but it seems like I am too new in awk to make it work. Let's assume that we have a file (eg. database.txt) (values are tab-separated): ...
2
votes
3answers
134 views

Delete lines containing repeated text

I have a file containing two paths on each line. I want to remove the lines containing the same path twice. I work on Linux and Solaris. I would like a one-liner in sed or awk or perl. Example input ...
2
votes
3answers
724 views

I want to find duplicates in a file and add a character to the end of the line on the 1st match

I am trying to find duplicates in a file and once a match is found mark the 1st match with a character or word on the end of the line. eg my file (test.html) contains the following entries host= ...
2
votes
2answers
1k views

Replacing text between two HTML Comments

I am new to the world of sed/awk and regex in general and have been studying their usage, but have been floundering trying to meet my need: I have an htm page that has a single line notice that needs ...
2
votes
3answers
154 views

Text to yaml conversion

I have a tab separated text file in this format: your-email your-order-id PayPal-transaction-id your-first-name your-second-name s@ess.com 12345 54321 sooky spooky t@tee.com 23456 ...
4
votes
2answers
709 views

Inotifywait for large number of files in a directory

What I want to do is, to monitor a directory (not recursive, just one) for new files created and append those files to one single big file as they are being written. The number of files that are ...
2
votes
3answers
1k views

Easy way to parse syslog date format

I'd like to write a script that analyses the last week's syslog. But my syslog logs in a stupid date format, e.g. "May 22". If it logged as 2013-05-22, this task would be trivial. Is there a way ...
1
vote
1answer
39 views

Matching hexadecimals with gawk

I have a binary file with the following content (printed in hexadecimal): $ xxd -p virus.com 5669727573b440bb0100b90500ba0000cd21 I can match the first 5 letters (which are the alphanumeric string ...
5
votes
2answers
191 views

awk + paste for cleaning up PATH?

I have seen this code in .cshrc init files on a few machines. I went through a few awk tutorials in trying to understand how it works, but I am still unable to decrypt it. setenv PATH `echo $PATH | ...
1
vote
3answers
429 views

awk a specific column with unexpected line break

I can't seem to find a solution for this and it's driving me crazy. I know I can use awk to print a column(s). I'm having trouble printing a specific column though because of the way my file system is ...
2
votes
3answers
58 views

Replace certain strings with value from former line

I have the following text: Source IP,URL 1.1.1.1,example1.com Blank,example2.com 2.2.2.2,example3.com Blank,example4.com Blank,example5.com Blank,example6.com Blank,example7.com 7.7.7.7,example8.com ...
3
votes
3answers
153 views

sed + how to remove character/s that start or ended on each number

How do I remove the . character(s) that start in the beginning of each number or end on each number? Remark – perl one liner also good alternative for sed. Example input: .23.12.44.5. .233.3.3.3 ...
3
votes
3answers
162 views

checking data in columns when a data or some may be missing or present?

I am not sure if this possible. say i have columns like : Team Colour Game Rainfall PlayerName XYZ Blue Cricket Yes Kapil suppose i need to search ...
2
votes
2answers
89 views

confuse with awk user define function

I have solved Projecteuler Problem 3, but the thing is that I am not able to create the function in awk. I have tried this working code (without function): #!/usr/bin/awk -f BEGIN{ ...
1
vote
1answer
505 views

Using awk to parse AIX's lsuser output in stanza format

I'm creating a simple awk script to parse AIX's lsuser -f ALL output and return information in one line. A sample of the output is something like this. root: id=0 pgrp=something ...
2
votes
6answers
166 views

How can I separate these two outputs using awk command

Here's my output: MessageID=3990592283244651750-30192b51.13df831d93a.7eb4;EsbTiming=2013-04-12T01:07:46.099 I want only the time. How can I separate them?
0
votes
1answer
145 views

moving columns across rows

I am dealing with a txt file and trying to keep the first column/field in place, but shift the 2nd column down by 1 row. I tried this, but it gave the error unmatched .'s. awk '{for(i=1; i<NR; ...
2
votes
3answers
3k views

How can I use SED or AWK to replace placeholders in a template file with variable content that contains special characters?

CentOS 6.3 I'm trying to get a small script to send an email containing a copy of email headers in the body (for the purpose of internal reporting). The template file contains the following: ...
4
votes
3answers
1k views

Remove string from a particular field using awk/sed

I have a file (>80,000 lines) that looks likes this: chr1 GTF2GFF chromosome 1 249213345 . . . ID=chr1;Name=chr1 chr1 GTF2GFF gene 11874 14408 . + . ...
0
votes
1answer
681 views

comparing lines with awk vs while read line

I have two files one with 17k lines and another one with 4k lines. I wanted to compare position 115 to position 125 with each line in the second file and if there is a match, write the entire line ...
3
votes
2answers
215 views

Automated partition selection in bash script

I'm trying to write a bash script to run from Linux on a CD or flashdrive that can mount Windows and change stuff, but I don't know how to go about detecting which partition/drive is Windows. My best ...
2
votes
2answers
1k views

Using bash shell function inside AWK

Is it possible to use bash function inside AWK somehow? Example file (string, int, int, int) Mike 247808 247809 247810 Trying to convert values from decimal to hexadecimal. Function defined ...
4
votes
1answer
702 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
409 views

Output of `java -version` not matched by grep or awk

On my Linux machine, it isn't clear to me why if I do the following then I don't get only the version string ("1.5.0_32"). # java -version | grep version | awk '{print $NF}' java version "1.5.0_32" ...
6
votes
4answers
2k views

How to remove multiple blank lines from a file?

I have some text-files I use to take notes in - just plain text, usually just using cat >> file. Occasionally I use a blank line or two (just return - the new-line character) to specify a new ...
1
vote
3answers
2k views

awk + print line only if the first field start with string as Linux1

how to print the line in case the first field start with Linux1 for example: echo Linux1_ver2 12542 kernel-update | awk '{if ($1 ~ Linux1 ) print $0;}' the target is to print the line , ...
1
vote
2answers
258 views

How to count the number of words and print the lines that match exactly a given pattern?

I want to count the number of words and print the matched pattern lines which matches exactly with following pattern: abc-ERROR: The input File contains: # abc-ERROR: xyxxkkfgfr # def-Error: ...
4
votes
4answers
599 views

How to remove character and space from a string

Hello I have one file with output Name : ABC Name : CDE Name : ZYS I want to get the result ABC CDE ZYS How can i get it through SED command. I have tried. sed s/'Name' but ...
6
votes
5answers
8k 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
56 views

Trimming one part if equal to another part?

I use an e-mail quote attribution string like this: On dd mmm yyyy hh:mm +hhmm, from info@example.org (Example Dot Org): where info@example.org is the sender's e-mail address and Example Dot Org is ...
5
votes
2answers
347 views

Gawk: Passing arrays to functions

Stuck with GNU awk 3.1.6 and think I've worked around its array bugs but still have what looks like a scope problem in a 600-line awk program. Need to verify understanding of array scope in awk to ...
1
vote
1answer
862 views

awk - gensub function

I need to insert contents of variable to parameter function gensub in awk, specifically instead of regular expression's parameter. Can you help me with it? I have: gawk ' BEGIN { a = ...
3
votes
2answers
334 views

cumulative totals with shifted column

Apologies in advance since I am sure this is an easy problem. Nevertheless, here goes. cat blah.txt aa+2 bb+4 cc+10 dd+31 I would like to process blah.txt to produce the folowing: aa+0 bb+2 cc+6 ...
1
vote
1answer
247 views

Safely convert unicode strings to printable characters

I have many HTML files containing mixed unicode strings like \303\243 and printable characters like %s. What I'd like to do is converting the unicode strings into printable characters in a safe way. ...
0
votes
2answers
202 views

Reordering strings in linux

How can I change lines around using the command line? e.g. I have these lines: Acct-Status-Type = Start User-Name = "37XXXXXXX" Event-Timestamp = "Apr 12 2013 15:56:55 AMT" I need to ...
0
votes
1answer
200 views

Regex awk to Cisco Interface

I would like to know if have some Sed/Grep or Awk regex to parse Cisco interface section, with specific attribute, like bellow. Content of file.txt ! interface FastEthernet0/1 no ip unreachables ! ...
0
votes
1answer
168 views

replacing text and deleting text using awk in file using

I have a script and I want to do some replace and delete operations on it. I used sed to extract values between words SendCommands and end like this sed -n '/SendCommands/,/end/p' ddtt As awk was ...
2
votes
1answer
639 views

Vim - how to increase each number in visual block?

I have the following SQL: update am.PERMISSIONS set PRM_ORDER = 35 PRM_VISIBLE = b'1' where PRM_ID = 3; update am.PERMISSIONS set PRM_ORDER = [35] PRM_VISIBLE = b'1' where PRM_ID = 7; update ...
1
vote
2answers
109 views

How do I get a field in bash's job list using awk?

I wanted to write a function to retrieve a field from the list of background jobs in bash. For example to get a specific argument. Let's say I send vim to the background, so "jobs" displays this ...
0
votes
3answers
361 views

Sorting IP address according to the second field in file

in my ksh script I need to add the following task ( OS - linux/solaris ) I have the following file more test.txt /etc/backup/app 172.1.120 172.110.120 /etc/backup/app 172.1.120.12 ...
-4
votes
1answer
139 views

How to transform two delimited ASCII files

These are 2 common delimited, text file transformation problems I'd like to find scripts to do (I dont know if awk or perl is best for these tasks). csh is the default shell on my Solaris10 unix ...