How can I remove first column with awk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I remove first column with awk?
# 8  
Old 08-16-2017
You perhaps have other options:-
Code:
sed 's/^.* //' input.txt              # Will give you just the last field, so I'm assuming you only have two.
cut -f2- -d" " input.txt              # Will give you all the columns except the first

perl -e 'foreach (<>) {
   @line=split / /;
   shift @line;
   print join (" ",@line)
}' < input.txt                        # Probably a bit long though (and I'm sure someone has a neater way, I'm new to Perl and just practising really)

More importantly, what do you want to do with the data? I'm assuming that this is not your real data and that you have a purpose in mind.

Is this part of a larger shell script perhaps? If you show us the code so far, we can help you work out a suitable solution.




Kind regards,
Robin

Last edited by rbatte1; 08-16-2017 at 08:56 AM..
This User Gave Thanks to rbatte1 For This Post:
# 9  
Old 08-16-2017
Code:
while read a b
do
   echo "$b"
done < infile

# 10  
Old 08-16-2017
Quote:
Originally Posted by cola
Is it possible to rewrite this code without 1? (using something like print)
Sure, the 1 is geek for {print}.
Code:
awk '{$1=""}{print}' input.txt

or
Code:
awk '{$1=""; print}' input.txt

$2="" would clear the 2nd column.

The following sed works similar but does not leave additional spaces
Code:
sed 's/[[:space:]]*[^[:space:]]\{1,\}[[:space:]]*//1' input.txt

//2 would be the 2nd column.
# 11  
Old 09-23-2017
Quote:
Originally Posted by MadeInGermany
Sure, the 1 is geek for {print}.
Code:
awk '{$1=""}{print}' input.txt

or
Code:
awk '{$1=""; print}' input.txt

$2="" would clear the 2nd column.

The following sed works similar but does not leave additional spaces
Code:
sed 's/[[:space:]]*[^[:space:]]\{1,\}[[:space:]]*//1' input.txt

//2 would be the 2nd column.
After deleting the first column there a leading space. How can I delete the first column with the extra space between first and second column?
# 12  
Old 09-23-2017
If you don't like ALL the other proposals in this thread, try
Code:
awk 'sub("^" $1 FS, _)' file
x
y
z

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk to remove specific column to one range

I need to remove specific column to one range source file 3 1 000123456 2 2 000123569 3 3 000123564 12 000123156 15 000125648 128 000125648 Output required 3 000123456 2 000123569 3 000123564 12 000123156 15 000125648 128 000125648 (6 Replies)
Discussion started by: ranjancom2000
6 Replies

2. Shell Programming and Scripting

Remove the values from a certain column without deleting the Column name in a .CSV file

(14 Replies)
Discussion started by: dhruuv369
14 Replies

3. Shell Programming and Scripting

Use grep/awk to remove part of column

hi all, how can i use grep or awk to clean the following input data: n<>the<>96427210 861521305 123257583 n<>obj<>79634223 861521305 79634223 n<>nmod<>68404733 861521305 68422718 where the desired results is to remove all non-numeric characters?: 96427210 861521305 123257583 ... (5 Replies)
Discussion started by: owwow14
5 Replies

4. Shell Programming and Scripting

Remove Specific Column in a File using awk

Hi, I would like to ask your expertise to remove specific column no. 8 in the below file using but I don't have an idea on how to simply do this using awk command. Appreciate your help in advance. Input f: ABC 1 1XC CDA 1 2YC CCC 1 3XC AVD 1 3XA Expected output file: ABC 1 1C CDA... (9 Replies)
Discussion started by: zzavilz
9 Replies

5. Shell Programming and Scripting

remove brackets and put it in a column and remove repeated entry

Hi all, I want to remove the remove bracket sign ( ) and put in the separate column I also want to remove the repeated entry like in first row in below input (PA156) is repeated ESR1 (PA156) leflunomide (PA450192) (PA156) leflunomide (PA450192) CHST3 (PA26503) docetaxel... (2 Replies)
Discussion started by: manigrover
2 Replies

6. Shell Programming and Scripting

need to remove duplicates based on key in first column and pattern in last column

Given a file such as this I need to remove the duplicates. 00060011 PAUL BOWSTEIN ad_waq3_921_20100826_010517.txt 00060011 PAUL BOWSTEIN ad_waq3_921_20100827_010528.txt 0624-01 RUT CORPORATION ad_sade3_10_20100827_010528.txt 0624-01 RUT CORPORATION ... (13 Replies)
Discussion started by: script_op2a
13 Replies

7. Shell Programming and Scripting

awk : Remove column1 and last column in a line

Hi All, How to remove col1 and last column in a line. Please suggest some awk stuffs. Input col1 col2 col3 col4 col1 col2 col3 col4 col5 col1 col2 col3 col4 col1 col2 col3 Output Processing col2 col3 ... Processing col2 col3 col4 ... Processing col2 col3 ... Processing... (5 Replies)
Discussion started by: k_manimuthu
5 Replies

8. Shell Programming and Scripting

Remove certain parameters from column using awk or sed

I have a text file Nov 1 LOG_10_000000343.gzip_COMPLETE 2910 server.log.3 Nov 4 LOG_10_000000343.gzip_COMPLETE 2910 server.log.4 Dec 5 LOG_10_000000343.gzip_blah 2910 server.log.5 Jul 6 LOG_10_000000343.gzip_ERROR 2910 server.log.1 I need to convert this to Nov 1 LOG_10_000000343.gzip... (3 Replies)
Discussion started by: gubbu
3 Replies

9. Shell Programming and Scripting

awk remove column with conditions?

Folks: I have a file which has 3 columns. Using awk I want to remove rows from column 3 (Col3 <> A) where it is not equal to A. All columns are seperated by "|". Col1|Col2|Col3|Col4 1 | 2 | A | 4 2 | 3 | A | 5 3 | 4 | B | 6 4 | 5 | A | 7 5 | 6 | ... (3 Replies)
Discussion started by: pr2003
3 Replies
Login or Register to Ask a Question