Remove first value in a delimited file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove first value in a delimited file
# 1  
Old 08-20-2014
Remove first value in a delimited file

Hi
I have two delimited files one with comma and other with new line
comma
Code:
1,2,3,4,5

I need to remove the first value of the file like below and only one line will there in the file

expected output
Code:
2,3,4,5

i thought of using cut command but is there any other way to do?

for the new line delimited file, the file will be like below

new line
Code:
1
2
3
4
5

Expected output
Code:
2
3
4
5

is there any way to do it

---------- Post updated at 08:58 PM ---------- Previous update was at 06:17 PM ----------

Hi
I have figured out to a way to cut the second value to end using the below
command,

Code:
cut -d ',' -f2- file1

but can someone please tell me on how to write to the same file

and i also found the below command for newline files

Code:
sed '1d' file1

and i'm struck with the same issue not knowing how to write to the same file
without using a temp file

thanks
MJ

Last edited by Scott; 08-20-2014 at 07:37 PM.. Reason: Code tags, please...
# 2  
Old 08-20-2014
You haven't said what OS you're using. The sed utility on some systems has a -i option to edit in-place, but it can be dangerous in some circumstances.

Why are you so against using a temp file? Using a temp file gives you an easy way to be sure you don't destroy your data if the cut or sed fails for some reason.
# 3  
Old 08-20-2014
Hi don,
thanks for responding , i'm using aix linux 2.6.16.60-0.99.1

if there is a way to use without the temp file i thought i could use that, i'm not using
this command in a script, its going to be used in an IBM application, so i dont want to make
the command too long, thats why

thanks
MJ
# 4  
Old 08-20-2014
I'm not sure what you mean by an IBM application, but in a ksh or bash script, the code:
Code:
sed '1d' file1 > file1.$$ && mv file1.$$ file1

seems to be pretty concise.
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 08-21-2014
For the possible problems connected with avoiding temporary files read Editing a File in Place.

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove new line characters from data rows in a Pipe delimited file?

I have a file as below Emp1|FirstName|MiddleName|LastName|Address|Pincode|PhoneNumber 1234|FirstName1|MiddleName2|LastName3| Add1 || ADD2|123|000000000 2345|FirstName2|MiddleName3|LastName4| Add1 || ADD2| 234|000000000 OUTPUT : ... (1 Reply)
Discussion started by: styris
1 Replies

2. Shell Programming and Scripting

Remove space before numbers in delimited file

Hi, I have a file which looks like this FORD|1333-1| 10000100010203| 100040507697|0002|356.45|5555| SSSSY|KKKKM|1000005|10| N096|10043| C987 I need the output to look like this FORD|1333-1|10000100010203|100040507697|0002|356.45|5555| SSSSY|KKKKM|1000005|10| N096|10043| C987 The leading... (8 Replies)
Discussion started by: wahi80
8 Replies

3. Shell Programming and Scripting

Remove blank columns from a tab delimited text file

Hello, I have some tab delimited files that may contain blank columns. I would like to delete the blank columns if they exist. There is no clear pattern for when a blank occurs. I was thinking of using sed to replace instances of double tab with blank, sed 's/\t\t//g' All of the examples... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

4. Shell Programming and Scripting

How to remove alphabets/special characters/space in the 5th field of a tab delimited file?

Thank you for 4 looking this post. We have a tab delimited file where we are facing problem in a lot of funny character. I have tried using awk but failed that is not working. In the 5th field ID which is supposed to be a integer only of that file, we are getting corrupted data as below. I... (12 Replies)
Discussion started by: Srithar
12 Replies

5. Shell Programming and Scripting

Remove Last field from a delimited file

Hi, I have a '~' delimited file and i want to remove the last field using awk. Please find the sample records below: 1428128~1~0~1100426~003~50220~005~14~0~194801~11~0~3~14~0~50419052335~0~0820652001~2~00653862 ~0~1~0~00126~1~20000110~20110423~R~ ~0~Z~1662.94~ ~002041~0045~Z~... (3 Replies)
Discussion started by: Arun Mishra
3 Replies

6. Shell Programming and Scripting

To remove duplicates from pipe delimited file

Hi some one please help me to remove duplicates from a pipe delimited file based on first two columns. 123|asdf|sfsd|qwrer 431|yui|qwer|opws 123|asdf|pol|njio Here My first record and last record are duplicates.As per my requirement I want all the latest records into one file. I want the... (12 Replies)
Discussion started by: ginrkf
12 Replies

7. Shell Programming and Scripting

Remove few columns from pipe delimited file

I have file as below column1|column2|column3|column4|column5| fill1|fill2|fill3|fill4|fill5| abc1|abc2|abc3|abc4|abc5| . . . . i need to remove column2,3, from that file column1|column4|column5| fill1|fill4|fill5| abc1|abc4|abc5| . . . (3 Replies)
Discussion started by: greenworld123
3 Replies

8. Shell Programming and Scripting

sed command to remove the first field from a '|' delimited file

Hi I have a file with fields delimited by |. I need to remove the first field from the file. I tried cut but it just extracts that field. sample.output abc|100|name1 cde|200|name2 efg|300|name3 Output should be sample.output 100|name1 200|name2 300|name3 thanks Var (6 Replies)
Discussion started by: var285
6 Replies

9. Shell Programming and Scripting

How to remove extra double quotes from string in a delimited file??

Hi Unix Gurus.. I am new to Unix. Please help me. The file I am getting is as follows: Input File "2011-07-06 03:53:23","0","I","NOT SET ",,,,"123985","SAW CUT CONCRETE SLAB 20"THICK",,"98.57","","EACH","N" "2011-07-06 03:53:23","0","I","NOT SET ",,,,"204312","ARMAFLEX-1 3/8 X... (2 Replies)
Discussion started by: BICC
2 Replies

10. Shell Programming and Scripting

Remove SPACES between PIPE delimited file

This is my input file with extra information in the HEADER and leading & trailing SPACES between PIPE delimiter. 02/04/2010 Dynamic List Display 1 --------------------------------------------------------------------------------------... (6 Replies)
Discussion started by: srimitta
6 Replies
Login or Register to Ask a Question