Visit Our UNIX and Linux User Community


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
# 1  
Old 02-28-2008
awk / grep / Prints all columns except the first one

I have the a file with the following data.

File Content.
1249 snf06.3.0 sw version 1.1 code MD5 192F MD4 MD3
1248 sns06.3.0 sw version 1.1 code MD5 192F MD12
1250 sns06.3.0 sw version 1.1 code MD5 192F0\ MD8
1241 sns06.3.0 sw code MD5 19
1243 sn06.3.0 sw version 1.1 code MD5 19
12 ss06.3.0 sw version 1.1 code MD5 192F
129 ss06.3.0 sw version 1.1 code MD5 192
139 sns06.3.0 sw version 1.1 code MD5 19
1219 se06.3.0 sw version 1.1 code MD5 19

I want to remove the first column from that file and my file should look like below.

Can someone help me how to Print all columns except the first one

Output file
----------

snf06.3.0 sw version 1.1 code MD5 192F MD4 MD3
sns06.3.0 sw version 1.1 code MD5 192F MD12
sns06.3.0 sw version 1.1 code MD5 192F0\ MD8
sns06.3.0 sw code MD5 19
sn06.3.0 sw version 1.1 code MD5 19
ss06.3.0 sw version 1.1 code MD5 192F
ss06.3.0 sw version 1.1 code MD5 192
sns06.3.0 sw version 1.1 code MD5 19
se06.3.0 sw version 1.1 code MD5 19

Thanks in advance
# 2  
Old 02-28-2008
Code:
cut -f2- -d ' ' input_file

# 3  
Old 02-28-2008
What does the hyphen after "-f2" do?
# 4  
Old 02-28-2008
It means: print all the fields (separated by space) starting from 2 and ending at the end of the line.
# 5  
Old 02-28-2008
There are Blank Spaces at the beginning of the file as well
so
cut -f2- -d ' ' file_name doesn't work

My requirement is I dont want the first column and everything after that till the end of the line I would like to see as an output.

so Except $1

awk '{print $2 till end of the line}' filename

File Content.
1249 snf06.3.0 sw version 1.1 code MD5 192F MD4 MD3
1248 sns06.3.0 sw version 1.1 code MD5 192F MD12
1250 sns06.3.0 sw version 1.1 code MD5 192F0\ MD8
1241 sns06.3.0 sw code MD5 19
1243 sn06.3.0 sw version 1.1 code MD5 19
12 ss06.3.0 sw version 1.1 code MD5 192F
129 ss06.3.0 sw version 1.1 code MD5 192
139 sns06.3.0 sw version 1.1 code MD5 19
1219 se06.3.0 sw version 1.1 code MD5 19
# 6  
Old 02-28-2008
Code:
awk '{ for(i=1; i<=NF; i++) {printf("%s ", $i)}
          print $NF
       } ' inputfile > outputfile

# 7  
Old 02-28-2008
There are blank spaces in the beginning of the line and after the end of first column. as shown below <BS> Blank Space
My output file should not contain the first column at all.


File Content.
<BS> <BS> 1249 <BS> snf06.3.0 sw version 1.1 code MD5 192F MD4 MD3
<BS> <BS> <BS> 1248 <BS> sns06.3.0 sw version 1.1 code MD5 192F MD12
<BS> <BS><BS> <BS>1250 <BS>sns06.3.0 sw version 1.1 code MD5 192F0\ MD8
<BS> <BS>1241 <BS>sns06.3.0 sw code MD5 19
<BS> <BS>1243 <BS>sn06.3.0 sw version 1.1 code MD5 19
<BS> <BS>12 <BS>ss06.3.0 sw version 1.1 code MD5 192F
<BS> <BS>129 <BS>ss06.3.0 sw version 1.1 code MD5 192
<BS> <BS>139 <BS>sns06.3.0 sw version 1.1 code MD5 19
<BS> 1219 <BS>se06.3.0 sw version 1.1 code MD5 19

Previous Thread | Next Thread
Test Your Knowledge in Computers #888
Difficulty: Easy
sed was developed from 1973 to 1974 by Bill Gates of Microsoft.
True or False?

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

Featured Tech Videos