Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

Need a linux script for remove the all line which end with /.

Hi expert,

Need a linux script for remove the all line which end  with /.

accounts/user1/
accounts/user1/pending cn 28.11.11.xls
accounts/user1/DELIVERY/
accounts/user1/DELIVERY/APRIL-12/
accounts/user1/MARCH 12/
accounts/user1/REPORTS/
accounts/user2/WORK.xls
accounts/user2/CONTRACT.xls

It show output like this:
accounts/user1/pending cn 28.11.11.xls
accounts/user2/WORK.xls
accounts/user2/CONTRACT.xls

remove line which end with /


Thanks & Regards,
Xerox
0
xeroxzerox
Asked:
xeroxzerox
  • 4
  • 4
  • 2
2 Solutions
 
Dan CraciunIT ConsultantCommented:
sed -i.backup '/\/$/d' ./infile
0
 
duncanb7Commented:
Linux command :

write it into other new outputfile.txt

sed   's/\///g' yourfile.txt >outputfie.txt

or

overwrite the same file yourfile.txt  after

 sed  -i   's/\///g' yourfile.txt
0
 
xeroxzeroxAuthor Commented:
Firstly Thanks for response.and script running great-fully  but it move some lines which end without / in backup file.
0
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

 
duncanb7Commented:
Could you attach your file in this thread ?
0
 
Dan CraciunIT ConsultantCommented:
@duncanb7: what does "\//" mean?
0
 
duncanb7Commented:
it should works

 tr "//\r" "\r" <yourfile.txt >outout.txt

it will only replace  the last "/" at the end of line
0
 
Dan CraciunIT ConsultantCommented:
@xeroxzerox: in infile.backup you have your original text. Including all the lines that end in "/".
The cleaned lines are in infile.
0
 
xeroxzeroxAuthor Commented:
HI duncanb7,
 your command output is
root@LEN-A70-198:/home/#  tr "//\r" "\r" 2013-11-28_ad.log > /home/outout.txt
tr: extra operand `2013-11-28_ad.log'
Try `tr --help' for more information.

Hi DanCraciun,
i do it but it only store 724 lines in orignal file & after, it send all lines in backup file include without / lines.
Why original file contain only 724 lines.if sed read all (30000 lines) then it store all lines.
0
 
Dan CraciunIT ConsultantCommented:
What sed -i.backup does is:
1. copy 2013-11-28_ad.log as 2013-11-28_ad.log.backup
2. delete lines from 2013-11-28_ad.log as per the regular expressions

If you do NOT want your original file modified, but instead copy the lines that don't end in "/" in another file, try this:

sed -n '/\/$/!p' ./2013-11-28_ad.log > 2013-11-28_ad.log.new
0
 
duncanb7Commented:
please also convert  dos to unix format  that make sure yourfile in unix format  by

 dos2unix  yourfile.txt output.txt  OR  on vi editor by :set fileformat=unix and save it

this is my final , please try it , it works at my side


sed 's/\/$//g' yourfile.txt>output.txt

Or  overwrite file

 sed -i 's/\/$//g' yourfile.txt
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now