Solved

A sed file

Posted on 2011-03-24
2
402 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
Comment Utility

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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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 …
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

16 Experts available now in Live!

Get 1:1 Help Now