Append and Prepend Text to a file list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append and Prepend Text to a file list
# 1  
Old 02-19-2009
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  
Old 02-19-2009
Should work Smilie
Code:
ls | sed 's/^/[[/;s/$/]]/'

# 3  
Old 02-19-2009
Thank you!

Quote:
Originally Posted by danmero
Should work Smilie
Code:
ls | sed 's/^/[[/;s/$/]]/'


Dynamite!
# 4  
Old 02-19-2009
Hammer & Screwdriver doing it with awk

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

# 5  
Old 02-19-2009
Clarify Code

Quote:
Originally Posted by joeyg
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 Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies

2. Shell Programming and Scripting

Gnu tool; sed awk echo etc to prepend or append string to a file

Looking to add text to a file, example File example; nodegroups: check-hosts: L@host.domain.com,host2.domain.com,host3.domain.com I need to take a file with a one line list of hosts separated by commas host.domain.com,host2.domain.com,host3.domain.comand prepend the string " ... (6 Replies)
Discussion started by: bash_in_my_head
6 Replies

3. Shell Programming and Scripting

Prepend text, different matched 1st letters

Prepending lines with: your, the, a or an based on 1st letter match. You'll see my problem below: sed '/^p\|^f\|^c\|^d\|^l/ s/^/your /' list.txt > your.txt && sed '/^v\|^j\|^k\|^m\|^n\|^s/ s/^/the /' your.txt > the.txt && sed '/^b\|^g\|^h\|^q\|^r\|^t\|^w\|^z/ s/^/a /' the.txt > a.txt && sed... (10 Replies)
Discussion started by: p1ne
10 Replies

4. Shell Programming and Scripting

How to append a text file?

i have to append a text file grep for a word, if found, put comment in starting of the line. here is an example cat test.sh bin/ksh Hello World Test Message :wq! search for "bin" word in test.sh file if found comment it out at starting of the line: Output as follows: #bin/ksh... (5 Replies)
Discussion started by: raghur77
5 Replies

5. Shell Programming and Scripting

sed prepend text ?

Hi, I have a file with email header information. I would like to change the Subject line. Subject: ** PROBLEM Host Alert: server.domainname is DOWN ** I'd like to change this line such as to look, Subject: serverID ACK Fw: ** PROBLEM Host Alert: server1.domainname is DOWN** How can I... (2 Replies)
Discussion started by: upengan78
2 Replies

6. Shell Programming and Scripting

awk text record - prepend first field to all subsequent fields

Hello everyone, I've suddenly gotten very interested in sed and awk (and enjoying it quite a bit too) because of a large conversion project that we're working on. I'm currently stuck with a very inefficient process for processing text blocks. I'm sure someone here should be able to easily point out... (2 Replies)
Discussion started by: jameswatson3
2 Replies

7. Shell Programming and Scripting

Script to append text from one file into another

Hello all. I was wondering if it possible to write a bash script that would do the following: I perform molecular modelling calculations and the output files are all text files with various different extensions. For example, I submit the input file "job_name.inp" and when it is done or the... (18 Replies)
Discussion started by: marcozd
18 Replies

8. Shell Programming and Scripting

prepend and append characters to the same line

Hi, I have a file 'tmp.dat' that contains the below data: 81763 40829 30405 80452 I want to prepend a ' character to the beginning of every line, and I want to append ', at the end of every line. Below is what I expect: '81763', '40829', '30405', '80452', Can anyone help me? ... (3 Replies)
Discussion started by: ChicagoBlues
3 Replies

9. UNIX for Dummies Questions & Answers

append a text to a file every month

i have something like below in my SAS code and every month i need to append a text say 'ext.hlc_sum0906' near ext.hlc_sum0905 and next month after ext.hlc_sum0906 i need to append this 'ext.hlc_sum0907' and so on like that.. is it possible using SED or some other command in unix? %let... (1 Reply)
Discussion started by: depakjan
1 Replies

10. Shell Programming and Scripting

how to append text into a file.

I have a command stream that will parse down an ftp DIR listing of a remote directory and return the name of the newest file that I am interested in. The command is sed -e '/^d/d' sppay.listing |sed -n -e '/SPPAY/p'|sort -r -k 43M,45 -k 47,48 -k 50,54|sed -n -e '1p'|cut -c 56-99 and what it... (2 Replies)
Discussion started by: beilstwh
2 Replies
Login or Register to Ask a Question