Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

A sed file

Posted on 2011-03-24
2
Medium Priority
?
450 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
[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
2 Comments
 
LVL 8

Accepted Solution

by:
point_pleasant earned 1000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
Suggested Courses

636 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