Solved

A sed file

Posted on 2011-03-24
2
408 Views
Last Modified: 2012-05-11
Hi, I have an self-training practice Trainingon bash command which needs help from you. Thank you in advance.
A long listing of the root directory, /, is used for input. Create a file holding sed commands that check for symbolic links and plain files. If a file is a symbolic link, precede it with a line "--This is a symlink--". If the file is a plain file, add a string on the same line, adding a comment like "<--this is a plain file".

Open in new window

0
Comment
Question by:zhshqzyc
2 Comments
 
LVL 8

Accepted Solution

by:
point_pleasant earned 250 total points
ID: 35207052

not a inline sed but gets the job done

ls -l / > /tmp/tmp_ls
while read inputline
do
        perms="$(echo $inputline | awk '{print $1}')"
        fn="$(echo $inputline | awk '{print $9}')"
        link_or_reg=`echo $perms | cut -c1`
        if [ "$link_or_reg" == "l" ]
        then
                echo "--This is a symlink-- \n$inputline"
        else
                echo "$inputline <--this is a plain file"
        fi

done < /tmp/tmp_ls
rm /tmp/tmp_ls
exit 0
0
 
LVL 23

Expert Comment

by:Maciej S
ID: 35207221
Works with GNU sed only (should be available in all linux distros).
Need some changes in other sed versions (in solaris for example).
ls -l / | sed '/^-/s/$/ <-- this is a plain file/;/^l/i\--This is a symlink--'

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now