|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Append text to files with a same pattern
Hi Folks, I wanted to know if i can use RegEx in a for-loop of a shell script. Here's a scenario, I have a set of files say x1, x2, x3..x9 in a directory(obviously with files other than this pattern). I want to append a line of text to all files that follow pattern x[1-9]. Can someone help me out? I know its simple. But i just cannot get it work. Code:
for i in "x[1-9]" do echo hello >> "$i" done I'm looking for something like the one above(which is not working for me). Last edited by Scrutinizer; 06-20-2012 at 10:28 AM.. Reason: code tags |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
make sure you are in the directory that contains those files or use their absolute path. Code:
cd $YOURDIR for i in x? do echo "hello" >>./$i done |
| The Following User Says Thank You to ctsgnb For This Useful Post: | ||
prithvirao17 (06-20-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Or this: Code:
#!/bin/ksh
cd ${working_dir}
ls x[1-9] | while read file
do
echo "hello" >> ${file}
done |
|
#4
|
|||
|
|||
|
Thanks. This one worked perfect.
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
The original solution is great; it just needs to lose the double quotes around the
x[1-9] .
Regards, Alister |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| append text to column in all files of directory | alpesh | Shell Programming and Scripting | 7 | 06-15-2012 01:33 PM |
| Append lines for a specific pattern | chitech | Shell Programming and Scripting | 7 | 02-23-2012 05:46 PM |
| Count Number Of lines in text files and append values to beginning of file | motoxeryz125 | UNIX for Dummies Questions & Answers | 7 | 04-28-2011 02:36 AM |
| sed: Find start of pattern and extract text to end of line, including the pattern | TestTomas | Shell Programming and Scripting | 5 | 05-27-2009 11:16 AM |
| how to append the pattern at the end of the line | aoussenko | Shell Programming and Scripting | 2 | 10-31-2008 03:06 PM |
|
|