How to skip first line from a file while manupulating the file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to skip first line from a file while manupulating the file
# 1  
Old 02-23-2009
How to skip first line from a file while manupulating the file

I need to put single quotes on the columns of a .csv file. The first row contains the column headers. I need to skip the first row and put quotes for rest of the rows. Would please someone help me with this.

Thanks

JP
# 2  
Old 02-23-2009
Tools

try tail +2
Some versions of unix will accept a tail +2 command to cut the file starting at the 2nd row. When done, concatenate your original and new files back together.
tail -1 file1 >file1.tmp
tail +2 file2 | ...commands... >file2.tmp
cat file1.tmp file2.tmp file1.new
# 3  
Old 02-23-2009
sed -e "2,$ s/,/','/g" -e "2,$ s/\(.*\)/'\1'/" testfile


sed -e "2,$ s/,/','/g" testfile | sed " s/\(.*\)/'\1'/"
# 4  
Old 02-23-2009
Quote:
Originally Posted by JPalt
I need to put single quotes on the columns of a .csv file. The first row contains the column headers. I need to skip the first row and put quotes for rest of the rows. Would please someone help me with this.

Thanks

JP
Code:
 awk 'NR>1{print "\047"$0"\047"}' file.csv

Regards
# 5  
Old 02-23-2009
Thanks
 
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 skip if file not found in bash?

Hello, I have a question regarding while loop and existence of files. I am running under ubuntu 18.04 bionic, have around fifty video files inside the directory. script: for file in *.mp4 do /root/bin/ffmpeg -i $file \ -i $(basename "${file/.mp4}").bs.srt \ -i $(basename... (12 Replies)
Discussion started by: baris35
12 Replies

2. UNIX for Dummies Questions & Answers

Using awk to skip record in file

I need to amend the code blow such that it reads a "black list" before the "print" statement; if "substr($1,1,6)" is found in the "blacklist" it will ignore that record and continue. the code is from an awk script that is being called from shell script which passes the input values. BEGIN { "date... (5 Replies)
Discussion started by: bazel
5 Replies

3. Shell Programming and Scripting

Split a large file in n records and skip a particular record

Hello All, I have a large file, more than 50,000 lines, and I want to split it in even 5000 records. Which I can do using sed '1d;$d;' <filename> | awk 'NR%5000==1{x="F"++i;}{print > x}'Now I need to add one more condition that is not to break the file at 5000th record if the 5000th record... (20 Replies)
Discussion started by: ibmtech
20 Replies

4. UNIX for Advanced & Expert Users

Read file and skip the line starting with #

Hi all, I'm new in unix. Need some help here. I have a file called server.cfg which contains the servers name, if I don't want to run on that server, I'll put a "#" infront it. username1@hostname.com username2@hostname.com #username3@hostname.com #username4@hostname.com... (17 Replies)
Discussion started by: beezy
17 Replies

5. Shell Programming and Scripting

want to skip a line in XML file using awk

HI All, I am trying to split a xml using awk. now the issue is i want to skip three lines from the xml file. first two and last one based on pattern. plz some one help. i am new to awk and struggling :wall: <?xml version="1.0"?> <notification> ..... ..... ..... ..... ........ (24 Replies)
Discussion started by: ganesan kulasek
24 Replies

6. UNIX for Dummies Questions & Answers

skip first line when doing a read of csv file

Folks, how do i skip the first line in a csv, while doing the read of a csv file in to a variable line by line. eg : do echo $line done < $rpt where rpt is path to csv file The initial 1st line is a garbage that i want to avoid, and start reading from 2nd line ... (2 Replies)
Discussion started by: venu
2 Replies

7. Shell Programming and Scripting

skip lines while reading a file

Hi Experts, I am tryin to read a file and while doing so i need to skip the lines which start with a hash (#) char. I thought of using a goto command but a lot of guys on this site say its not the good way to program. Moreover I am using a ksh shell which deos not support goto command. ... (4 Replies)
Discussion started by: bankimmehta
4 Replies

8. Shell Programming and Scripting

Manupulating Records in a fixed width file

I am trying to determine what would be a fast and simple way to manipulate data that comes in a fixed width format. This data has 6 segments within a record. Each record needs to written out with a header and the 6 segments. Based on the value in column #6 the fields will be defined accordingly.... (4 Replies)
Discussion started by: Muga801
4 Replies

9. Shell Programming and Scripting

AWK to skip comments in XML file

Hello, I'm trying to make a shell script to skip comments from an XML file, but with the code below only deletes comments that are in one line. Can you tell me what can be added here? nawk ' { if($0 !~/<!--/) { a=0 } if($0 ~/<!--/ && $0 ~/-->/) {a=1} if($0 ~/<!--/) {a=1} if... (1 Reply)
Discussion started by: majormark
1 Replies

10. UNIX for Dummies Questions & Answers

skip reading certain lines in a file

How can I exclude reading lines in a file that contains the following: filesystem:/home/pach/liv_patches 128005120 88456640 37270758 71% /home/patches That is, all lines that contain and begins with filesystem: should not be processed/read from a file (5 Replies)
Discussion started by: paulsew
5 Replies
Login or Register to Ask a Question