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
Solved

A sed file

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

861 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