Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-11-28
10
Medium Priority
?
357 Views
Last Modified: 2013-11-28
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
Comment
Question by:xeroxzerox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 1400 total points
ID: 39682940
sed -i.backup '/\/$/d' ./infile
0
 
LVL 13

Expert Comment

by:duncanb7
ID: 39682965
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
 
LVL 6

Author Comment

by:xeroxzerox
ID: 39682979
Firstly Thanks for response.and script running great-fully  but it move some lines which end without / in backup file.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 13

Expert Comment

by:duncanb7
ID: 39682984
Could you attach your file in this thread ?
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39682985
@duncanb7: what does "\//" mean?
0
 
LVL 13

Expert Comment

by:duncanb7
ID: 39682993
it should works

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

it will only replace  the last "/" at the end of line
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39682996
@xeroxzerox: in infile.backup you have your original text. Including all the lines that end in "/".
The cleaned lines are in infile.
0
 
LVL 6

Author Comment

by:xeroxzerox
ID: 39683012
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
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39683026
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
 
LVL 13

Assisted Solution

by:duncanb7
duncanb7 earned 600 total points
ID: 39683050
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

Featured Post

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question