appending


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting appending
# 1  
Old 02-08-2005
appending

i've been fiddling around with append and I know how to append a word into a file, but how would you go about appending a word to a filename?
# 2  
Old 02-08-2005
Code:
  f=`echo filename$word`
   mv filename $f

# 3  
Old 02-08-2005
while read word; do
mv filename.txt 'echo filename$word.txt'
# 4  
Old 02-08-2005
It all depends on what you mean by "append a word to a filename"

If you're doing it for a single file, then it's as simple as

mv my_file my_file_new

If you are doing it via a script, simple variables can be used to manipulate the filename...

Code:
...
filename="my_file"
append="new"

mv ${filename} ${filename}_${new}
...

You can do this en masse too....
Code:
cd /where/my/files/are

ls | while read filename; do
   mv ${filename} ${filename}_new
done

There is more than one way to skin a cat, and the method depends on the type of cat being skinned Smilie What exactly are you trying to achieve?

Cheers
ZB
# 5  
Old 02-09-2005
I'm just fooling around with the scripts, so thanks for all your inputs. I really like unix, but I sometimes find the error messages ambiguous. Hopefully with more practice, I'll know what the script errors are complaining about.
# 6  
Old 02-09-2005
FWIW: PERL has an option to automatically do it, the -i option, so you can run perl on a file or files, have perl "do nothing" and append an extension. Check out the -i option, below;

Code:
Usage: perl [switches] [--] [programfile] [arguments]
  -0[octal]       specify record separator (\0, if no argument)
  -a              autosplit mode with -n or -p (splits $_ into @F)
  -C              enable native wide character system interfaces
  -c              check syntax only (runs BEGIN and CHECK blocks)
  -d[:debugger]   run program under debugger
  -D[number/list]set debugging flags (argument is a bit mask or alphabets)
  -e 'command'    one line of program (several -e's allowed, omit programfile)
  -F/pattern/     split() pattern for -a switch (//'s are optional)
  -i[extension]   edit <> files in place (makes backup if extension supplied)
  -Idirectory     specify @INC/#include directory (several -I's allowed)
  -l[octal]       enable line ending processing, specifies line terminator
  -[mM][-]module  execute `use/no module...' before executing program
  -n              assume 'while (<>) { ... }' loop around program
  -p              assume loop like -n but print line also, like sed
  -P              run program through C preprocessor before compilation
  -s              enable rudimentary parsing for switches after programfile
  -S              look for programfile using PATH environment variable
  -T              enable tainting checks
  -t              enable tainting warnings
  -u              dump core after parsing program
  -U              allow unsafe operations
  -v              print version, subversion (includes VERY IMPORTANT perl info)
  -V[:variable]   print configuration summary (or a single Config.pm variable)
  -w              enable many useful warnings (RECOMMENDED)
  -W              enable all warnings
  -X              disable all warnings
  -x[directory]   strip off text before #!perl line and perhaps cd to directory

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Matching and appending

I have two files FILEA a/b/c/d e/f/g/h i/j/k/l m/n/o/p FILEB i/j/k/l i want that if lines of FILEB matches lines of FILEA then matching lines in FILEA to be appended by word "MATCH" NEW FILEA a/b/c/d e/f/g/h i/j/k/l "MATCH" m/n/o/p I have tried following script .but not... (6 Replies)
Discussion started by: shaan4uster
6 Replies

2. Shell Programming and Scripting

Appending value to variable

I have a Query! by using command cat >> file1 we can append data's to a already existing file, Similarly is it possible to append a data to a variable. Thanks in Advance!! (2 Replies)
Discussion started by: gwgreen1
2 Replies

3. UNIX for Dummies Questions & Answers

Appending error

Hi All, I just want to append the value in variable at the end of the file. var=1234 sed -e "$a $var" file1 > file 2. But I get this error sed: -e expression #1, char 4: unknown command: `1' Kindly let m know how can I do that... (5 Replies)
Discussion started by: waqar1
5 Replies

4. Shell Programming and Scripting

appending two strings

Hi, I have a small doubt. Here is the code snippet for which the output that I'm getting are a bit surprising. testing.sh #!/bin/sh arg_1=$1 echo "arg passed by user is:${arg_1}" mapping=`grep ${arg_1}= testing.conf | awk -F"=" '{print $2}'` echo "mapping is $mapping"... (4 Replies)
Discussion started by: badrimohanty
4 Replies

5. Shell Programming and Scripting

Appending variables

Hi, I'm having a problem with something I can't really figure out by myself. I've tried to do it with a for loop, but I'm pretty sure it won't work, if I'm not mistaken. Basically, what I'm trying to do is test some variables and if any of them is not empty, add the values of these variables... (5 Replies)
Discussion started by: mutex1
5 Replies

6. Shell Programming and Scripting

Appending date

hi All, Searched forum but couldn't find a solution to this problem: How can I append a file with date in the ninth line? ie I want to insert a line with the current date and time in the ninth line. I tried this: date=`date` awk 'NR==9 {printf "'$date' \n"} {print $0}' abc.log below... (10 Replies)
Discussion started by: Sreejith_VK
10 Replies

7. Shell Programming and Scripting

appending with AWK

Hi all, I have two files called INPUT1 and INPUT2 and i am trying to append the values of INPUT1 to INPUT2 using AWK. The INPUT1 file will always has a single field and the INPUT2 file has 3 fields but both files will have same number of records always. Following is the format of the... (5 Replies)
Discussion started by: harris2107
5 Replies

8. Shell Programming and Scripting

Appending to a variable?

Hey, I'm creating a custom useradd script, and I'm giving the option to add secondary groups. Basically what I want to do is ask for the name of the group, you type in the group you want to add, it assigns that group name to the variable $sgroup. Then the scripts asks if you want add another. If... (0 Replies)
Discussion started by: paqman
0 Replies

9. Shell Programming and Scripting

appending

hi, a1.txt ------ xyz zxc xya xdf a2.txt ------ a1 a2 b1 b2 cat a1.txt >> a2.txt -->its appending at the end (6 Replies)
Discussion started by: mohan705
6 Replies

10. UNIX for Dummies Questions & Answers

Appending out to a file

Hi, once again - Ok here it is: a).I used the touch command to create a file (touch directory.list) b).I then added this line: - date '+The date is %a %h %d, %Y %nIt is %I:%M %p' > directory.list -So that this date function would go at the top of my script c).Now I want to display a... (1 Reply)
Discussion started by: Astudent
1 Replies
Login or Register to Ask a Question