Help in removing 1st column in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in removing 1st column in file
# 1  
Old 08-30-2010
Help in removing 1st column in file

Hi All,
I have a input file
Code:
CT;RE23;DR33;FT44
CT;RE24;DR22;FT55

Here i need to make and output file with below structure i need to remove the first column:
Code:
RE23;DR33;FT44
RE24;DR22;FT55

How can i do this do i need to write a for loop for this

Moderator's Comments:
Mod Comment Having 19 posts you should be familiar with using code tags.

Last edited by zaxxon; 08-30-2010 at 12:37 PM..
# 2  
Old 08-30-2010
Code:
cut -d";" -f2- file

# 3  
Old 08-30-2010
I am also a beginner but this will work, may be there is bttr way to do it also
Code:
awk '  { print $2 $3}'  testfile1 >>newfile

# 4  
Old 08-30-2010
Quote:
Originally Posted by shashi792
I am also a beginner but this will work, may be there is bttr way to do it also
Code:
awk '  { print $2 $3}'  testfile1 >>newfile

No, it will not work.

Code:
awk 'BEGIN{FS=OFS=";"}  { print $2, $3,$4}'  testfile1

So above cut command is more convenient.
# 5  
Old 08-31-2010
For completeness, here is one way of achieving what you want using sed
Code:
sed 's/\([^;]*;\)\(.*$\)/\2/g' file

# 6  
Old 08-31-2010
Try this
Code:
awk -F\; '{$1=""}1' test.txt

# 7  
Old 08-31-2010
Quote:
Originally Posted by posix
Try this
Code:
awk -F\; '{$1=""}1' test.txt

This is not what the OP expected, did you test the code before posting?

Quote:
Originally Posted by fpmurphy
For completeness, here is one way of achieving what you want using sed
Code:
sed 's/\([^;]*;\)\(.*$\)/\2/g' file

Not necesarry to use a first "remembered pattern" Smilie:
Code:
sed 's/[^;]*;\(.*\)/\1/' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies

2. Shell Programming and Scripting

Removing duplicates on a single "column" (delimited file)

Hello ! I'm quite new to linux but haven't found a script to do this task, unfortunately my knowledge is quite limited on shellscripts... Could you guys help me removing the duplicate lines of a file, based only on a single "column"? For example: M202034357;01/2008;J30RJ021;Ciclo 01... (4 Replies)
Discussion started by: Rufinofr
4 Replies

3. Linux

Print the 1st column and the value in 2nd or 3rd column if that is different from the values in 1st

I have file that looks like this, DIP-17571N|refseq:NP_651151 DIP-17460N|refseq:NP_511165|uniprotkb:P45890 DIP-17571N|refseq:NP_651151 DIP-19241N|refseq:NP_524261 DIP-19241N|refseq:NP_524261 DIP-17151N|refseq:NP_524316|uniprotkb:O16797 DIP-19588N|refseq:NP_731165 ... (2 Replies)
Discussion started by: Syeda Sumayya
2 Replies

4. Shell Programming and Scripting

How to use regex on particular column (Removing comma from particular column)?

Hi, I have pipe separated file which contains some data having comma(,) in it. I want to remove the comma(,) only from particular column without changing data in other columns. Below is the sample data file, I want to remove the comma(,) only from 5th column. $ cat file1 ABC | DEF, HIJ|... (6 Replies)
Discussion started by: Prathmesh
6 Replies

5. Shell Programming and Scripting

Grep/Awk on 1st 2 Letters in 2nd Column of File

Hi everyone. I need to change a script (ksh) so that it will grep on the 1st 2 letters in the second column of a 5 column file such as this one: 192.168.1.1 CAXY0_123 10ABFL000001 # Comment 192.168.1.2 CAYZ0_123 10ABTX000002 # Comment 192.168.2.1 FLXY0_123 11ABCA000001 ... (4 Replies)
Discussion started by: TheNovice
4 Replies

6. Shell Programming and Scripting

Removing duplicate records in a file based on single column explanation

I was reading this thread. It looks like a simpler way to say this is to only keep uniq lines based on field or column 1. https://www.unix.com/shell-programming-scripting/165717-removing-duplicate-records-file-based-single-column.html Can someone explain this command please? How are there no... (5 Replies)
Discussion started by: cokedude
5 Replies

7. Shell Programming and Scripting

Removing duplicate records in a file based on single column

Hi, I want to remove duplicate records including the first line based on column1. For example inputfile(filer.txt): ------------- 1,3000,5000 1,4000,6000 2,4000,600 2,5000,700 3,60000,4000 4,7000,7777 5,999,8888 expected output: ---------------- 3,60000,4000 4,7000,7777... (5 Replies)
Discussion started by: G.K.K
5 Replies

8. Shell Programming and Scripting

Using sed on 1st column of tab delimited file

Hi all, I'm new to Unix and work primarily in bioinformatics. I am in need of a script which will allow me to replace "1" with "chr1" in only the first column of a file which looks like such: 1 10327 rs112750067 T C . PASS ASP;RSPOS=10327;... (4 Replies)
Discussion started by: Hkins552
4 Replies

9. Shell Programming and Scripting

Strings from one file which exactly match to the 1st column of other file and then print lines.

Hi, I have two files. 1st file has 1 column (huge file containing ~19200000 lines) and 2nd file has 2 columns (small file containing ~6000 lines). ################################# huge_file.txt a a ab b ################################## small_file.txt a 1.5 b 2.5 ab ... (4 Replies)
Discussion started by: AshwaniSharma09
4 Replies

10. UNIX for Dummies Questions & Answers

removing trailing spaces of a particular column in a file

Hi, I am currently confused. Suppose I have a file something like the one below. 4299|raj Telecommunications|12||||| 4302|anjali International Ltd.|86|ritchie||dong|(000)2890 9993 |(222)4881 3689 4305|フィデュシアリ・ト-スト・インター...ショ...ル投資顧問株式会社 |112||||01-9211-1931 |08-3677-1985 Now... (2 Replies)
Discussion started by: rooh
2 Replies
Login or Register to Ask a Question