The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
prepend columns to a file ChicagoBlues UNIX for Dummies Questions & Answers 3 10-22-2008 02:00 PM
Append text at end of the first line in a file catgovind Shell Programming and Scripting 7 05-01-2008 08:33 AM
read list of filenames from text file, archive, and remove fxvisions Shell Programming and Scripting 5 03-20-2007 09:56 PM
how to append text into a file. beilstwh Shell Programming and Scripting 2 03-06-2007 05:51 PM
can I save list of files in memory and not in text file? umen Shell Programming and Scripting 1 06-05-2006 05:27 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-19-2009
CapnDoody CapnDoody is offline
Registered User
  
 

Join Date: Feb 2009
Location: North-East USA
Posts: 3
Append and Prepend Text to a file list

I want to print out a directory listing, then append [[ to the beggining and ]] to the end of each line. I'm trying to create a list of Wiki links based on folder listings that i can just copy and paste without having to edit 100's of file listings.

Using sed i've figured out to do something like this:

sed "s/$/]]/g" documentation.txt > test.txt

How do i do the prepend? And how do i put this into one line of code that i can possibly pipe the directoryling listing to sed..

ls /documentation | sed .... etc


Thanks!

CapnDoody (Chris)
  #2 (permalink)  
Old 02-19-2009
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,441
Should work

Code:
ls | sed 's/^/[[/;s/$/]]/'

  #3 (permalink)  
Old 02-19-2009
CapnDoody CapnDoody is offline
Registered User
  
 

Join Date: Feb 2009
Location: North-East USA
Posts: 3
Thank you!

Quote:
Originally Posted by danmero View Post
Should work

Code:
ls | sed 's/^/[[/;s/$/]]/'

Dynamite!
  #4 (permalink)  
Old 02-19-2009
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink doing it with awk


Code:
ls | awk '{print "[["$0"]]"}'

  #5 (permalink)  
Old 02-19-2009
CapnDoody CapnDoody is offline
Registered User
  
 

Join Date: Feb 2009
Location: North-East USA
Posts: 3
Clarify Code

Quote:
Originally Posted by joeyg View Post
Code:
ls | awk '{print "[["$0"]]"}'

Can you break down that code for me? What is $0 doing for us? Placeholder for each line starting at 0?

How would is use awk if i wanted to input a file and output to new file?


Code:
 awk '{print "[["$0"]]"}' firstfile.txt >> newfile.txt

Thanks! Just not really versed in awk (and by that i mean i have no idea how to use it
Closed Thread

Bookmarks

Tags
sed prepend append text

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0