Solved

A sed file

Posted on 2011-03-24
2
417 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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 …
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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