Use command to get a parameter and add extension


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use command to get a parameter and add extension
# 1  
Old 03-23-2012
Bug Use command to get a parameter and add extension

Hi,

I'd like to get something like:

Input:
Code:
my_command FILE

Output to command line:
Code:
my_command FILE.ext1 FILE.ext2

explained:
I want to provide a filename without extension and it should be given out like a command with the filename+extension1 and filename+extension2.

I'd assume this should be done simply in a shell.
Maybe anyone also knows soultions which can fulfill this as AWK/SED script?!

Thanks and best regards!

====
Edit:
Maybe I should more explain that the issue is to call the command. Should be very simple...
Code:
#!/bin/sh
echo "this shows params as wanted output: $1.log and $1.ref"
echo "-----------------------------------------------------------------------------"
echo "This is wanted outcome but as USED command, not printed only:"
echo "mycommand $1.log $1.ref"
echo "-----------------------------------------------------------------------------"
echo "Solution could be somthing like... (maybe i need `$1`or "$1" or other command as system?!)"
system("mycommand $1.log $1.ref");


Last edited by unknown7; 03-23-2012 at 11:13 AM.. Reason: Added code example
# 2  
Old 03-23-2012
Not sure...
All I can see is that your "command" is the same... but does not the same so I would imagine a first script that formats for you (correct command and output) then to not call the correct but the one that formats, you put it elsewhere and use an alias :
Code:
alias correct_command='/path_2_format_command'

Its Friday, I may not be very clear...

Demo:
With command touch:
Code:
ant:/home/vbe/wks/test $ ll
total 4
drwxrwxr-x   2 vbe        bin             96 Mar 23 15:22 .
drwxr-xr-x   4 vbe        bin           2048 Mar 23 15:19 ..
-rw-rw-r--   1 vbe        bin              0 Mar 23 15:20 file
ant:/home/vbe/wks/test $ cat ../testing
touch $1.txt $1.log
ant:/home/vbe/wks/test $ alias touch='../testing'
ant:/home/vbe/wks/test $ touch file                 
ant:/home/vbe/wks/test $ ll
total 4
drwxrwxr-x   2 vbe        bin             96 Mar 23 15:23 .
drwxr-xr-x   4 vbe        bin           2048 Mar 23 15:19 ..
-rw-rw-r--   1 vbe        bin              0 Mar 23 15:20 file
-rw-rw-r--   1 vbe        bin              0 Mar 23 15:23 file.log
-rw-rw-r--   1 vbe        bin              0 Mar 23 15:23 file.txt
ant:/home/vbe/wks/test $


Last edited by vbe; 03-23-2012 at 11:25 AM.. Reason: added demo...
This User Gave Thanks to vbe For This Post:
# 3  
Old 03-23-2012
Not exactly what you said but you gave me the point...
the issue is, I used an alias as my_command.
So workaround is easy: replacement of the alias with the command in it.

Now it works perfect... no system needed - thanks a lot!
Most times it's easier as you think and I thought some kind of system call is needed :-)

Maybe any1 knows if and how I can use aliases in an bash script?
# 4  
Old 03-23-2012
Putting your aliases in .bashrc does not suffice?

I would suggest more looking at using functions in your script...
Well look above example if I forget to unalias touch, I will be wondering what is going on next week...
Alias affects all your environment, using functions can be specific to an application, script (or your environment if you put them there...).
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find command + replace the extension (.xxx) by *

Hello, I'm on HP Unix and in a Job, I tried to extract all files from a folder, and replace the extension (.xxxx) by '*' , remove duplicates and move the result in a file.. Example : Folder has : ABC, CCC.txt, CCC.sf, CCC.sfd, DDD I need to generate and output file with : ... (6 Replies)
Discussion started by: royinfo.alain
6 Replies

2. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

3. Shell Programming and Scripting

How to add the dat time stamp just before the last extension of a file?

hi, A file name is in the form inside a variable FILE_NAME="s1.txt.xls" i want to append date and time stamp inbetween s1.txt and .xls. so after appending date time stamp the file name would be MOD_FILE_NAME="s1.txt.201307251422.xls" currently i am using the below code... (4 Replies)
Discussion started by: Little
4 Replies

4. Shell Programming and Scripting

Command that takes one parameter and then searches for the passed in parameter

Hi I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/ Can anyone please help me on this? (3 Replies)
Discussion started by: pankaj80
3 Replies

5. UNIX for Dummies Questions & Answers

Find command to exclude files with no extension

The below 'ls' command will list down files with extensions and suppress the ones with no extension ls |grep "\\." But this dosen't work when I apply the same logic using 'find' command find . -type f |grep "\\." I need help on how this logic can be implemented using 'find' command (3 Replies)
Discussion started by: meenavin
3 Replies

6. Shell Programming and Scripting

ksh command to rename all files with no extension

hi! i want to rename all files with no extension with the extension DAT. with this command ls |grep -v "\\." i can list files but i dont know how i am going to rename them.. so i tried FILE_LIST=ls |grep -v "\\." for TEST_FILE in ${FILE_LIST} do mv $TEST_FILE... (2 Replies)
Discussion started by: kouppoua
2 Replies

7. Shell Programming and Scripting

Script to add extension to filename

Hi all, I have a folder with a bunch of files in them, and I would like to add an extension (.mp3)to all these filenames. The folder has only files that I'd like .mp3 added to. It looks something like this: Intput: File1 File2 File3Output: File1.mp3 File2.mp3 File3.mp3Thanks in... (2 Replies)
Discussion started by: repiv
2 Replies

8. Shell Programming and Scripting

Add text before extension

Hi , I have a txt file , in which there are multiple lines, I want to add .1cdb before each .txt file. Source data DB_SOURCE=DWHCBU #Generate_file=/root/cbu/src/ET_CDR_SCAN.txt(# is a part of the data) TARGET=DWHEDW #Generate_TG_FILE=/root/cbu/src/ET_CDR_SCAN.txt DB_SOURCE=DWHCBU... (3 Replies)
Discussion started by: mora
3 Replies

9. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies
Login or Register to Ask a Question