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
# 8  
Old 02-28-2008
awk '{ for(i=1; i<=NF; i++) {printf("%s ", $i)}
print $NF
} ' inputfile > outputfile

this didnt work either, all it did was removed the blank spaces.
the first column is still there with the rest of the line.
# 9  
Old 02-28-2008
Well change the loop to read for(i=2; i<=NR;i++)

I did not catch the requirment on not printing $1
# 10  
Old 02-28-2008
Another one with awk:

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

# 11  
Old 02-28-2008
awk '{$1="";$0=substr($0,2)}1' file > outfile
awk: syntax error near line 1
awk: bailing out near line 1

awk '{ for(i=2; i<=NF; i++) {printf("%s ", $i)} print $NF } ' inputfile > outputfile

with this the first column does get disappeared but the rest of the columns are repeated.

for example

this is what I had in the input file

1477 wgtnge01.5.1
1477 wgtngp01.1.1
1477 wgtngp02.1.1
1477 witge01.11.0
1477 witge01.11.1
1477 witge01.11.3
1477 witge01.15.
1477 witge01.5.
1477 witge01.6.0

This is what I got in the output file.

wgtnge01.5.1 wgtnge01.5.1
wgtngp01.1.1 wgtngp01.1.1
wgtngp02.1.1 wgtngp02.1.1
witge01.11.0 witge01.11.0
witge01.11.1 witge01.11.1
witge01.11.3 witge01.11.3
witge01.15. witge01.15.
witge01.5. witge01.5.
witge01.6.0 witge01.6.0
# 12  
Old 02-28-2008
wc inputfile
31355 63475 776666 inputfile

awk '{ for(i=2; i<=NR; i++) {printf("%s ", $i)} print $NF } ' inputfile > outputfile
awk: trying to access field 100
record number 100
# 13  
Old 02-28-2008
Originally Posted by knijjar
awk '{$1="";$0=substr($0,2)}1' file > outfile
awk: syntax error near line 1
awk: bailing out near line 1
Use nawk or /usr/xpg4/bin/awk on Solaris

# 14  
Old 02-28-2008

Perfect , Thanks alot, now you are my nawk/awk guru. Smilie
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