简体   繁体   中英

Remove ',' fromove last line of the file

I have flat file with data as

cast ( (emp_ID)  as varchar(2000) ),
cast ( (emp_name)  as varchar(2000) ),

I want to remove the , from the last line in this file. The output should be:

 cast ( (emp_ID)  as varchar(2000) ),
 cast ( (emp_name)  as varchar(2000) )

I am using the following command:

tail -1 select_stmnt.txt | sed 's/,/''/g' >> select_stmnt.txt

What I get is:

  cast ( (emp_ID)  as varchar(2000) ), 
  cast ( (emp_name)  as varchar(2000) ),
  cast ( (emp_name)  as varchar(2000) )

Removal of the , is working fine, but instead of the modified line replacing the original, it is appended, which I don't want.

You can try this:

sed '$ s/,$//g' yourInputFile

The first dollar($) will be used to select the last line.

使用-i就地编辑文件:

sed -i '$s/,$//' select_stmnt.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM