[Linux-disciples] lost+found files

Adam Rosi-Kessel adam at rosi-kessel.org
Thu Sep 30 17:41:41 EDT 2004


On Thu, Sep 30, 2004 at 04:36:12PM -0400, Nirmal Trivedi wrote:
> > file * | grep "ASCII" | sed -e "s/^#//g" -e "s/:.*//g" | xargs cat | less
> > That should display them all to the screen.
> That pretty much worked. I like the "sed" command! I had to run it
> without "s/^#//g" for it to execute properly. Not sure what that does,
> but I know without it, I'll retain the "#" that I need to access the
> ASCII files. 
> Talk about gibberish. Don't know even know what these symbols mean and
> I'm editing scripts! I suppose it's not to dissimilar from literary
> work. :)

Oops.  Yeah.  sed is actually not as abstruse as it sounds.  You
understand the file | grep part, I assume.

sed runs expressions on its (piped) input.  You can specify multiple
expressions with -e.  The expressions in this case are just simple search
and replace:

s/searchstring/replacestring/g

The /'s delimit the search string and replace string, the g means
"global" -- search and replace all instances -- but is actually
unnecessary here.

^# means "the character # falling at the beginning of a line."  I was
removing the #'s from the output of file, but I forgot that the files are
actually named with the #, so that was a bad move.

:.* means "the character : followed by anything."  So this is to get rid
of all the output after the :, telling you what type of file it is.

This gets piped into xargs, which takes its input and turns it into the
argument for any given command, in this case 'cat', which displays the
named file to the screen.

Finally, it's piped into less, so that you can see screens one at a time.

You can try simple things like:

echo nirmal trivedi | sed -e "s/^n/b/" -e "s/triv.*/the cat/"

To see how sed works; try changing the expressions and the echo command
as an experiment.
-- 
Adam Rosi-Kessel
http://adam.rosi-kessel.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20040930/7412c1fc/attachment.pgp


More information about the Linux-disciples mailing list