Copy filepath along with filename at end of another file

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Copy filepath along with filename at end of another file
# 1  
Old 05-31-2017
Copy filepath along with filename at end of another file

Hi ,

Please help me out for the below problem -

I have 2 files in a directory -

Code:
$ ls -ltr
total 4
-rwx------+ 1 abc Domain Users 615 May 31 17:33 abc.txt
-rwx------+ 1 abc Domain Users   0 May 31 17:33 ll.sh

I want to write the filename of abc.txt along with the directory to the end of the line of ll.sh
So current entry in ll.sh is

Code:
command.sh

I want it as

Code:
command.sh dir/abc.txt

Please help me out
# 2  
Old 05-31-2017
One way:
Code:
 printf "command.sh %s/abc.txt" $(pwd) >> ll.sh

This will only work when the current directory is the same as both files: abc.txt and ll.sh
# 3  
Old 05-31-2017
Too little information. Is the command.sh the only line in ll.sh? In your sample directory listing it has size 0, so it can't possibly hold that (partial) line. Is there only one single other file in the directory, or, if not, do features exists to tell the target file from others? What shell/version do you use?
With a recent bash that provides extended globbing and process substitution, try
Code:
shopt -s extglob
ls !(*.sh) | cat <(tr '\n' ' ' <ll.sh) - > /tmp/TMP
mv /tmp/TMP ll.sh

or even
Code:
{ tr '\n' ' ' <ll.sh; ls !(*.sh); } > /tmp/TMP
mv /tmp/TMP ll.sh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sha256 , copy file to new filename

Hello, i want to create a sha256 hash for a file and copy the source file under new filename as : sha256hash_sourcefilename Input : sha256sum FILE Example : sha156sum mounttest.123 Output HASH_FILE How to do this ? e.g.: ... (1 Reply)
Discussion started by: bdittmar
1 Replies

2. Shell Programming and Scripting

Copy contain file to end another file

Hi All, How I can paste contain big file1 to end another file2, e.g., $cat file1 aaaaa bbbbb ccccc$cat file2 11111 22222 3333 4444 55555 66666 7777 8888then want like paste contain file1 to end file2 > file3 $cat file3 aaaaa bbbbb ccccc 11111 22222 3333 4444 55555 66666... (4 Replies)
Discussion started by: aav1307
4 Replies

3. Shell Programming and Scripting

* in end of filename

Hi, i have some files which looks like given below: -rwxrwxrwx 1 amsbatch ams 1608 Oct 22 2009 AMS_BATCH_COMPILE* -rwxr----- 1 amsbatch ams 1608 Oct 22 2009 AMS_BATCH_COMPILE_original* -rwxrwxrwx 1 amsbatch ams 1127 Dec 1 2005 AMS_LMU.sh* drwxr-xr-x 2... (3 Replies)
Discussion started by: mann2719
3 Replies

4. Shell Programming and Scripting

How to add filepath to filename when moving it?

Hi I have a cron job setup that searches for 'core dump' files in a fixed set of directories and moves the core files to a separate file system. I am able to add date and time info to the file name. How can I add the source directory path to the file name? In case anyone is wondering why I... (5 Replies)
Discussion started by: dexter126
5 Replies

5. Shell Programming and Scripting

Copy a file with backslash in the filename

Hi, I'm trying to make a script that copy a file that has a backslash in the filename. What I'm doing wrong? The flename is: 1300212744.H786972P30819.ns1.cybernet.com.br,S\=6313:2, My script ParteA="1300212970.H27173P31627.ns1.cybernet.com.br,S" ParteB=\\ ParteC="=" ParteZ=":2,"... (15 Replies)
Discussion started by: Ronaldo
15 Replies

6. UNIX for Dummies Questions & Answers

How to copy/move to a file with a special character as the 1st char in the filename?

I am trying to create files with special characters in its filenames for testing purposes. This is on a Linux RHEL4 but this should also be applicable on a Unix shell. I am able to create files with special characters in the filenames...e.g. cp -pv foo.gif \*special.gif cp -pv foo.gif \... (6 Replies)
Discussion started by: sqa777
6 Replies

7. Shell Programming and Scripting

Grab a number at end of filepath

Hello, I have a file path such as: /path/to/whatever/30 and I want to get the number off the end. My problem is that there might be other numbers in the path and the last number can be 1 or 2 digits. I tried something like: sed 's/.*\(\/\{1,2\}\).*/\1/' which seems to work fine for single digit... (7 Replies)
Discussion started by: phreezr
7 Replies

8. Shell Programming and Scripting

tar: extract single file to different filepath

Hi, This is my first post here - I'm hoping I can get some help! I have searched these forums and othersand not getting anything that works. I am trying to extract a single file from a tar archive to a diffierent location than it will default to. For example my tar log shows me ... a... (3 Replies)
Discussion started by: littleIdiot
3 Replies

9. Shell Programming and Scripting

How to add filename to the end of each line in file

Hi, I'm reading data from comma separated files to DB. Now there is a need to have the name of the input file in each row of that file. How can I do this in unix script? Example: $cat file1 value11,value12, value,13 value21,value22, value,23 value31,value32, value,33 And the result... (2 Replies)
Discussion started by: tmikahan
2 Replies

10. Shell Programming and Scripting

Grabing Date from filename and adding to the end of each line in the file.

Hi, I have 24 .dat files something like below. The file name starts with “abc” followed by two digit month and two digit year. Is there a way to grab the month and year from each filename and append it to the end of each line. Once this is done I want to combine all the files into file... (1 Reply)
Discussion started by: rkumar28
1 Replies
Login or Register to Ask a Question