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?
# 1  
Old 08-16-2017
How can I remove first column with awk?

cat input.txt
Code:
a x
b y
c z

Expected output
Code:
x
y
z

# 2  
Old 08-16-2017
Hello cola,

Could you please try following and let me know if this helps you.
Solution 1st: To get by 2nd field in code.
Code:
awk '{print $2}'   Input_file

Solution 2nd: Considering your Input_file has only 2 fields so getting the last field of it then.
Code:
awk '{print $NF}'   Input_file

Solution 3rd: Using cut command for this task may help too.
Code:
cut -d" " -f2   Input_file

Thanks,
R. Singh
# 3  
Old 08-16-2017
Another solution in awk. Just empty the first field and print the line

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

This User Gave Thanks to itkamaraj For This Post:
# 4  
Old 08-16-2017
Try also
Code:
colrm 1 2 <file
x
y
z

This User Gave Thanks to RudiC For This Post:
# 5  
Old 08-16-2017
Quote:
Originally Posted by itkamaraj
Another solution in awk. Just empty the first field and print the line

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

$1 is the first column, first column is replaced by null string. But what is 1 here?

Last edited by cola; 08-16-2017 at 09:16 AM..
# 6  
Old 08-16-2017
The one is a boolean (truth) value. It means print this line. So the command removes the first field then prints what is left.
# 7  
Old 08-16-2017
Quote:
Originally Posted by jim mcnamara
The one is a boolean (truth) value. It means print this line. So the command removes the first field then prints what is left.
Is it possible to rewrite this code without 1? (using something like print)
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

Featured Tech Videos