Deleting the first column with sed,awk or perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting the first column with sed,awk or perl
# 1  
Old 09-05-2010
Deleting the first column with sed,awk or perl

Code:
336 brtr
256 hello

Output:
Code:
brtr
hello

How can i do this with sed,awk or perl?
# 2  
Old 09-05-2010
I think this will do the trick:

Code:
sed -E 's/^[^ \t]*[ \t]+//'

It matches from the beginning of the line, all characters that are not whitespace (space or tab) and then all whitespace and replaces that with nothing. The -E is needed for sed in either a Berkeley environment or with AT&T's AST version of sed. Otherwise I believe -r is needed.
# 3  
Old 09-06-2010
Code:
sed 's/[ \t]*[^ \t]*[ \t]*//' infile

Code:
awk '{$1=x;sub(OFS,x)}1' infile

# 4  
Old 09-06-2010
Code:
perl -ne 'print ((split / /,$_)[1])'

If only two fields, then use the above to skip the 0th ( first ) field.

Last edited by Franklin52; 09-06-2010 at 04:09 AM.. Reason: code tags
# 5  
Old 09-06-2010
Well, if it were only 2 fields then you could also use:
Code:
awk '{print $2}'

or
Code:
sed 's/.*[ \t]//'

no?
# 6  
Old 09-06-2010
Code:
$ 
$ cat f1
336 brtr
256 hello
$ 
$ perl -lne 'print substr($_,rindex($_," ")+1)' f1
brtr
hello
$ 
$ perl -lne '/^(.*?) (.*?)$/ && print $2' f1
brtr
hello
$ 
$ perl -lne 'print ((split)[1])' f1
brtr
hello
$ 
$ perl -plne '$_=((split)[1])' f1
brtr
hello
$ 
$ perl -plane '$_=$F[1]' f1
brtr
hello
$ 
$ perl -plne 's/^.*? //' f1
brtr
hello
$ 
$ 

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk/sed summation of one column based on some entry in first column

Hi All , I am having an input file as stated below Input file 6 ddk/djhdj/djhdj/Q 10 0.5 dhd/jdjd.djd.nd/QB 01 0.5 hdhd/jd/jd/jdj/Q 10 0.5 512 hd/hdh/gdh/Q 01 0.5 jdjd/jd/ud/j/QB 10 0.5 HD/jsj/djd/Q 01 0.5 71 hdh/jjd/dj/jd/Q 10 0.5 ... (5 Replies)
Discussion started by: kshitij
5 Replies

2. Shell Programming and Scripting

Solution for replacement of 4th column with 3rd column in a file using awk/sed preserving delimters

input "A","B","C,D","E","F" "S","T","U,V","W","X" "AA","BB","CC,DD","EEEE","FFF" required output: "A","B","C,D","C,D","F" "S", T","U,V","U,V","X" "AA","BB","CC,DD","CC,DD","FFF" tried using awk but double quotes not preserving for every field. any help to solve this is much... (5 Replies)
Discussion started by: khblts
5 Replies

3. Shell Programming and Scripting

awk or sed: change the color of a column w/o screwing up column spacing

Hey folks. I wrote a little awk script that summarizes /proc/net/dev info and then pipes it to the nix column command to set up column spacing appropriately. Here's some example output: Iface RxMBytes RxPackets RxErrs RxDrop TxMBytes TxPackets TxErrs TxDrop bond0 9 83830... (3 Replies)
Discussion started by: ryran
3 Replies

4. Shell Programming and Scripting

Deleting column using awk

How Can we delete a range of coloumns using awk? (or any other method is fine) If we have a file which has about 200 coloumns. I need to delete a particular range lets say for eg from $6 to $119 Can we do this using cut, if yes the cut command would also be helpful. many thanks in... (4 Replies)
Discussion started by: Sri3001
4 Replies

5. Shell Programming and Scripting

deleting lines between patterns using sed or awk

hi, Here is excerpt from my xml file <!-- The custom module to do the authentication for LDAP --> </login-module> <login-module code="com.nlayers.seneca.security.LdapLogin" flag="sufficient"> <module-option... (1 Reply)
Discussion started by: sunrexstar
1 Replies

6. Shell Programming and Scripting

Awk or Sed, fubd match in column, then edit column.

FILE A: 9780743551526,(Abridged) 9780743551779,(Unabridged) 9780743582469,(Abridged) 9780743582483,(Unabridged) 9780743563468,(Abridged) 9780743563475,(Unabridged) FILE B: c3saCandyland 9780743518321 "CANDYLAND" "MCBAIN, ED" 2001 c3sbCandyland 9780743518321 ... (7 Replies)
Discussion started by: glev2005
7 Replies

7. Shell Programming and Scripting

Deleting characters with sed,perl,awk

Input: :: gstreamer :: xine-lib :: xine-lib-extras Output should be: gstreamer xine-lib xine-lib-extras How can it be done with sed or perl? (12 Replies)
Discussion started by: cola
12 Replies

8. Shell Programming and Scripting

Deleting a line from a file with sed and awk?

cat file.txt fvnuiehuewf ruevhxncvkjrh zxjvurhfuwe jkhvBEGINvfnvf ijrgioe Trying to delete a line that has the pattern "BEGIN" cat sedtest filename=file.txt pattern=BEGIN sed "/^$pattern/d" "$filename" (9 Replies)
Discussion started by: cola
9 Replies

9. UNIX for Dummies Questions & Answers

Trim String in 3rd Column in Tab Delimited File...SED/PERL/AWK?

Hey Everybody, I am having much trouble figuring this out, as I am not really a programmer..:mad: Datafile.txt Column0 Column1 Column2 ABC DEF xxxGHI I am running using WGET on a cronjob to grab a datafile, but I need to cut the first three characters from... (6 Replies)
Discussion started by: rickdini
6 Replies

10. Shell Programming and Scripting

deleting particular lines and moving a line up using perl/sed

Hi, I need convert a dump file in the following format : (please note that line numbers are provided for easy look) Original file: 1 2007-10-2482.90 No trade 0 0.00 100000.00 2 100000.00 3 0.00 4 HOLD 5 2007-10-2589.75 Bought 1114 1114 100000.00 0.00 ... (5 Replies)
Discussion started by: sabyasm
5 Replies
Login or Register to Ask a Question