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

cut -f2- -d ' ' input_file

What does the hyphen after "-f2" do?

It means: print all the fields (separated by space) starting from 2 and ending at the end of the line.

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

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

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

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.

Well change the loop to read for(i=2; i<=NR;i++)

I did not catch the requirment on not printing $1

Another one with awk:

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

Regards

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

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

Use nawk or /usr/xpg4/bin/awk on Solaris

Regards

Franklin52

Perfect , Thanks alot, now you are my nawk/awk guru. :b:

now would you be kind enough try to explain what it really did.

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

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

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 :slight_smile:

Thanks in advance

@zanetti321

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

@knijjar

An explaination of the command:

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