delete first column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete first column
# 1  
Old 12-21-2009
delete first column

Dear All,

I need to delete the first column, which blank in the tab delimited file and i need to print all the other columns with out disturbing the format of the file.

I have tried with the followings and its not working for my case

Code:
awk '{$1=""}1' file > newfile

Code:
cut -d, -f2- data

Can anyone help me in this regard?

Expecting your replies and thanks in advance.

Warm regards
Fredrick.
# 2  
Old 12-21-2009
To replace the content of the first column with "":

Code:
awk 'BEGIN{FS=OFS="\t"}{$1="";}1' file

To remove the first column and the first fieldseparator:

Code:
awk 'BEGIN{FS=OFS="\t"}{$1="";sub("\t","")}1'  file

# 3  
Old 12-21-2009
Tools Need to chose other cut option

try with the c option, as in
Code:
ls | sort | cut -c2-

which will display all your filenames, sorted, but then the first character removed
# 4  
Old 12-21-2009
with perl

Code:
perl -wln -e 'print $1 if /^\w+\s(.*)$/' In_file



---------- Post updated at 10:34 PM ---------- Previous update was at 10:30 PM ----------

Quote:
Originally Posted by Franklin52
To replace the content of the first column with "":

Code:
awk 'BEGIN{FS=OFS="\t"}{$1="";}1' file

To remove the first column and the first fieldseparator:

Code:
awk 'BEGIN{FS=OFS="\t"}{$1="";sub("\t","")}1'  file

Hello, somehow it doesnt work for me.
Code:
gaurav@localhost:~$ cat hello.txt 
name gaurav
college bit
name alex
college bangalore institute
city bangalore /bengaluru
gaurav@localhost:~$ awk 'BEGIN{FS=OFS="\t"}{$1="";}1' hello.txt 





gaurav@localhost:~$ awk 'BEGIN{FS=OFS="\t"}{$1="";sub("\t","")}1' hello.txt 





gaurav@localhost:~$

Can you point where I am going wrong.?
Regards.
# 5  
Old 12-21-2009
Quote:
Originally Posted by gaurav1086
Code:
perl -wln -e 'print $1 if /^\w+\s(.*)$/' In_file



---------- Post updated at 10:34 PM ---------- Previous update was at 10:30 PM ----------



Hello, somehow it doesnt work for me.
Code:
gaurav@localhost:~$ cat hello.txt 
name gaurav
college bit
name alex
college bangalore institute
city bangalore /bengaluru
gaurav@localhost:~$ awk 'BEGIN{FS=OFS="\t"}{$1="";}1' hello.txt 





gaurav@localhost:~$ awk 'BEGIN{FS=OFS="\t"}{$1="";sub("\t","")}1' hello.txt 





gaurav@localhost:~$

Can you point where I am going wrong.?
Regards.
It's not a tab delimited file.
# 6  
Old 12-21-2009
Tools ah

hello ,
sorry my mistake.
thanks.

---------- Post updated at 10:59 PM ---------- Previous update was at 10:55 PM ----------

Code:
perl -wln -e 'print $1 if /^\w+\s+(.*)$/' in_file

# 7  
Old 12-21-2009
Replace first column with spaces:
Code:
awk '{gsub(/./," ",$1)}1' OFS="\t" infile

Empty first column:
Code:
awk '{$1=""}1' OFS="\t" infile

Delete first column:
Code:
sed 's/^[^\t]*[\t]//' infile

Code:
cut -f2- infile


Last edited by Scrutinizer; 12-21-2009 at 02:42 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete part of a column

I want to delete a part of the 4th column from the given file below: <Text Text_ID="10155645315851111_10155645333076543" From="460350337461111" Created="2011-03-16T17:05:37+0000" use_count="123">This is the first text</Text> <Text Text_ID="10155645315851111_10155645317023456"... (2 Replies)
Discussion started by: my_Perl
2 Replies

2. Shell Programming and Scripting

Delete last characters in each column

I need to delete the last 11 characters from each number and they are all in the same line (each is in a different column): -6.89080901827020800000 3.49348891708562325136 1.47988367839905286876 -2.29707635413510400000 -3.49342364708562325136 -4.43758473239905286876 -2.29707635413510400000... (14 Replies)
Discussion started by: rogeriog.em
14 Replies

3. Shell Programming and Scripting

Delete a row if either of column value is zero

Hi, My input file is this way 1.1 0.0 2.4 3.5 7.9 1.8 22.3 4.7 8.9 0.9 1.3 0.0 3.4 5.6 0.0 1.1 2.2 0.0 0.0 1.1 0.0 0.0 3.4 5.6 I would like to delete the entire row, if either of 2nd and 3rd columns are 0.0. Please note that my values are all decimal values. So, my output would... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

4. Shell Programming and Scripting

Delete Space between last and first column

HI Input A R04 tion=1 Li 51599 R08 tiea=1 Li 51995 R11 ocatea=1 Li 51992 R12 nArea=1 Li ... (2 Replies)
Discussion started by: asavaliya
2 Replies

5. Shell Programming and Scripting

delete the same column

var1 var2 var3 var4 var5 var6.... A G A T G T G A A A A A A A A A A A G A G T A T let's call this "file1.txt" we can see that var2 and var5 have the idential values. I would like to make a script so that if any variables (could be more than 2) have the identical values, i want to... (4 Replies)
Discussion started by: johnkim0806
4 Replies

6. Shell Programming and Scripting

Delete certain column awk

Hi experts, I have a file, where inside this file contains multiple columns (up to 2000 columns): 0.05 0.54 2.02 0.21 1.39 2.92 0.31 1.75 3.34 I want to delete column 3,6,9,12,15,18,21... etc (any columns where can be divided from value 3), so that results is like: 0.05 0.54 0.21 1.39... (6 Replies)
Discussion started by: guns
6 Replies

7. Shell Programming and Scripting

delete a column in XML file

I have any XML ouput file(file name TABLE.xml), where the data is loaded in A SINGLE LINE, I need need help in writting a ksh shell script which gives me the output which should not have column S_NO This is my input file which has S_NO column. <?xml version="1.0"... (4 Replies)
Discussion started by: pred55
4 Replies

8. Shell Programming and Scripting

Delete first row last column

Hi All, I am having following file and I want to delete 1 row last column. Current File Content: ================ procedure test421 put_line procedure test321 test421 procedure test521 test321 procedure test621 test521 Expected File Content: =========================== procedure... (3 Replies)
Discussion started by: susau_79
3 Replies

9. UNIX for Dummies Questions & Answers

to delete a column in unix

Hai Please let me know the command in unix(command mode ) from a file that deletes the whole column (not 1st and last column )& replace with numbers starting from 1. Regards suneetha. (8 Replies)
Discussion started by: gaddesuneetha
8 Replies

10. Shell Programming and Scripting

Search for by column and delete line

I have a file with thousands of lines. I need to search for a specific value in a specific field and delete the lines that match. example. abcdXX1234567 abcdXY1234567 abcdXX1234567 abcdXX1234567 If there is an XY in position 5 and 6 then remove that line. Any suggestions would... (4 Replies)
Discussion started by: thudak
4 Replies
Login or Register to Ask a Question