LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-26-2007, 05:45 PM   #1
chellemybelle
LQ Newbie
 
Registered: Nov 2007
Location: OK
Distribution: Fedora 4 -I think
Posts: 7

Rep: Reputation: 0
Question Append string to end of file name


Hello,

I am trying to append "_EMPTY" to the end of a bunch of empty files in the same directory. I am able to list the files to be appended with this:

find /Users/iannelson/Desktop/EmptyFile -size +0

I have tried various methods of sed and awk to append, but I really haven't found a good example that explains how to use them, so i can't figure out what is necessary. Also, I'm not certain that I can get it done with one line, I may need a for loop. Here is one of my for loops:
for file in ?; do
apname=${_EMPTY}
mv $file '$apname'
done
*Not sure what to put for the ?.

or this one:

for loopEmptyFiles in $emptyfiles
do
originName=$(echo $loopEmptyFiles|awk '{?}');
newName=$ originName"_EMPTY"
echo "Appending $newName";
done

*Not sure what goes between the brackets.

Any help would be greatly appreciated. I also have a few more scripts I could use some help on, hope I don't overwhelm you guys
 
Old 11-26-2007, 06:46 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Why would you need to add "empty"? ls -l shows what is empty already. In a script, "find <path> -size 0" will find them. (-size 0, not -size +0)

I'm thinking there has to be a way of doing this with "find .....|xargs mv", but I don't have it yet.
 
Old 11-26-2007, 06:49 PM   #3
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
find /Users/iannelson/Desktop/EmptyFile -size 0 -execdir mv {} {}_empty \;

should work
 
Old 11-26-2007, 06:56 PM   #4
chellemybelle
LQ Newbie
 
Registered: Nov 2007
Location: OK
Distribution: Fedora 4 -I think
Posts: 7

Original Poster
Rep: Reputation: 0
Yeah, I know it's kinda goofy, but that's my assignment. I have to create or locate a directory and list all the zero length files, then append "_EMPTY" to each of them. And when I did:

find /Users/iannelson/Desktop/EmptyFile -size +0 w/o the "+" it didn't list the files.
 
Old 11-26-2007, 07:17 PM   #5
chellemybelle
LQ Newbie
 
Registered: Nov 2007
Location: OK
Distribution: Fedora 4 -I think
Posts: 7

Original Poster
Rep: Reputation: 0
Alright this kinda worked:

find /Users/iannelson/Desktop/EmptyFile -size +0 -execdir mv {} {}_EMPTY \;

I had to put the +0 in because it doesn't work at all if I don't. Also it renames all the files in the directory, even ones that are not empty. Thank you though, that got me further along.
 
  


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
bash programming-append single line to end of file pheasand Linux - General 4 02-28-2014 09:41 AM
Append variable string(s) at end of each line schaganti Linux - Newbie 2 10-19-2007 01:31 PM
How can I append text to a string in a file HGeneAnthony Linux - Newbie 4 03-01-2007 12:16 PM
bash: append string to end of line khairil Programming 6 02-27-2007 05:09 AM
batch append string to the end of a determined line in text files osio Programming 6 06-30-2005 09:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:11 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration