awk / grep / Prints all columns except the first one


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk / grep / Prints all columns except the first one
# 15  
Old 02-28-2008
now would you be kind enough try to explain what it really did.

nawk '{$1="";$0=substr($0,2)}1' file > outfile
# 16  
Old 02-28-2008
Please Help Guys

Dear All

I have a pattern which look like this:

2 20080224_04:11:14.021 ISC-Libya BritishTelecom1 68 IAM 249129406720 218926283155 b 3943 ACM f 11117 REL b 11224 RLC :COMMA: NCI=10,FCI=6101,CPC=0A,TMR=00,OFI=80,USI: :COMMB: BCI=1234: :RELCAUSE:10:


2 20080224_04:10:03.578 ISC-Libya BritishTelecom2 38 IAM 20186946784 218927207018 b 646 ACM b 3060 CPG b 21348 ANM f 81542 REL b 81712 RLC :COMMA: NCI=10,FCI=6101,CPC=0A,TMR=00,OFI=80,USI: :COMMB: BCI=0234: :RELCAUSE:1F:

I have alot of these samples and they are placed in files which is created every 15 minutes of name (CDR.Date1) and then after 15 minutes (CDR.date2) and so on

Note that the arrangement of the fields is not fixed at all but i need every time to print a certain fields.

I want the output to be :

ISC-Libya British-Telecom2 b f b
ISC-Libya British-Telecom2 b b b f b

as you see the character b and character f repeated in the same pattern so i want a script as soon as it find any b or any f or any ISC-Libya or British Telecom to print it with the same order it comes with inside the pattern.

Please Reply thanks in advance
# 17  
Old 02-28-2008
Just comment

in my last question please i would like output to be like this

ISC-Libya British-Telecom2 b f b 10
ISC-Libya British-Telecom2 b b b f b 1F

No change in the message conepts just output format Smilie

Thanks in advance
# 18  
Old 02-29-2008
@zanetti321

Don't hijack a thread but start a new one.

@knijjar

An explaination of the command:

Code:
nawk '{$1="";$0=substr($0,2)}1' file > outfile

$1="" -> empty the first field
$0=substr($0,2) -> start the whole line at the second position and ignore the space at the first position
1 -> awk evaluates this as true and the default action is to print the line

Hope this helps.


Regards

Last edited by Franklin52; 02-29-2008 at 07:35 AM.. Reason: grammatical correction
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: BEGIN: prints nothing

My code fails to do anything if I've BEGIN block in it: Run the awk script as: awk -f ~/bin/sum_dupli_gene.awk make_gene_probe.txt #!/usr/bin/awk -f BEGIN { print ARGV #--loads of stuff } END{ #more stuff } (14 Replies)
Discussion started by: genome
14 Replies

2. Shell Programming and Scripting

awk prints only last line

data.txt: NEWTEXTS="frq=63,std=-0.00533584,time=Mar-21-(09:15:03)-2016,epoch=1458576903,avg=64.2059,212.698 frq=197,std=0.587585,time=Mar-21-(09:16:02)-2016,epoch=1458576962,avg=64.2059,483.756 frq=178,std=0.503514,time=Mar-21-(09:46:02)-2016,epoch=1458578762,avg=64.2059,500... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. Shell Programming and Scripting

awk prints unwanted new lines

Hello, I need a little help with the following: I'm using AWK to read input from a comma-seperated value file, and only printing certain fields like so: awk -F "," '{print $1,$3,$6}' /list.csv | tail -1 Which outputs the following: server1 APPID OS I run into a problem... (8 Replies)
Discussion started by: LinuxRacr
8 Replies

4. Shell Programming and Scripting

Include information in certain columns using grep and awk

HI all, I have data in a file that looks like this: 1 HOW _ NNP NNP _ 3 nn _ _ 2 DRUGS _ NNP NNP _ 3 nn _ _ 3 ACT _ NNP NNP _ 0 null _ _ 4 : _ ... (3 Replies)
Discussion started by: owwow14
3 Replies

5. Shell Programming and Scripting

Compare intervals (columns) from two files (awk, grep, Perl?)

Hi dear users, I need to compare numeric columns in two files. These files have the following structure. K.txt (4 columns) A001 chr21 9805831 9846011 A002 chr21 9806202 9846263 A003 chr21 9887188 9988593 A003 chr21 9887188 ... (2 Replies)
Discussion started by: jcvivar
2 Replies

6. Shell Programming and Scripting

grep/awk to only print lines with two columns in a file

Hey, Need some help for command to print only lines with two columns in a file abc 111 cde 222 fgh ijk 2 klm 12 23 nop want the ouput to be abc 111 cde 222 ijk 2 Thanks a lot in advance!!! (3 Replies)
Discussion started by: leo.maveriick
3 Replies

7. Shell Programming and Scripting

awk (gawk) grep & columns

Hi, I'm working with gawk (on DOS) today. A goal is: find a string for-instance '123', cut a line in two columns and write second one. The problem is: command line works OK, awk file doesn't. But I would like to work with file because there are many strings to find. input: line command: awk... (4 Replies)
Discussion started by: frajer
4 Replies

8. Shell Programming and Scripting

Display output as columns using grep/awk/sed

I have several files with say something like cat sparrow I can grep for "cat" and "sparrow" and usually the output is one below the other cat sparrow How can I view these as columns say Pets Birds cat sparrow Would be great if this can be on command line using awk or... (1 Reply)
Discussion started by: gubbu
1 Replies

9. Shell Programming and Scripting

awk system() prints extra 0 -- why?

Here's the command I'm running: # echo "hi" | awk '{etime = system("hostname") ; close("hostname") ; print etime""}' And here's the ouput: server.domain.tld 0 Why in the world is that second line, the one that's just "0", there? Many thanks in advance. (2 Replies)
Discussion started by: treesloth
2 Replies

10. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies
Login or Register to Ask a Question