LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-04-2005, 01:05 PM   #1
rheza
LQ Newbie
 
Registered: Apr 2003
Distribution: Slackware
Posts: 21

Rep: Reputation: 15
Shell Script (adding a prefix to output lines)


Hello, I'd like to ask about a command in the shell which would allow me to add a prefix to the an output of mulitple lines. Like say when I do a command:

ls

is there a way to prefix it outputs with a string "string here" such that it will look like this

string here file1
string here file2
string here file3
string here anotherfile

instead of

file1
file2
file3
anotherfile
 
Old 01-04-2005, 01:13 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Code:
#!/bin/bash

ls | while read FILENAME ; do
	echo "String here $FILENAME"
done
 
Old 01-04-2005, 01:15 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Or just:
Code:
ls | sed 's/.*/string here &/'
 
Old 01-04-2005, 01:18 PM   #4
rheza
LQ Newbie
 
Registered: Apr 2003
Distribution: Slackware
Posts: 21

Original Poster
Rep: Reputation: 15
I wasn't really using it for ls, but the second one works great. Thanks Hko!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script adding autostart gnome script Coolrunr Programming 3 01-01-2009 02:23 PM
Why prefix shell script with "./" ? seeDubya Linux - Newbie 5 08-29-2005 01:53 AM
shell script output redirection goral.j Programming 3 01-27-2005 05:34 AM
Shell Script for Gzipping with date output Junior41180 Programming 1 10-16-2004 06:39 AM
shell script to copy lines from a file Warmduvet Programming 2 09-14-2004 09:25 PM


All times are GMT -5. The time now is 03:23 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration