Results 1 to 6 of 6
i am a newbie in linux script. i try to manipulate the param input name and get the expected output.
Here is example;
#! /bin/ksh
# $1 -< proj_request_tmp_table
param1=$1
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 01-17-2013 #1Just Joined!
- Join Date
- Oct 2012
- Posts
- 22
shell script-remove certain characters
i am a newbie in linux script. i try to manipulate the param input name and get the expected output.
Here is example;
#! /bin/ksh
# $1 -< proj_request_tmp_table
param1=$1
#using cut or sed remove _tmp
export param1
echo "output: $param1 print out"
#--end of script
after remove _tmp here is my
expected output:output: proj_request_table print out
thanks in advance
- 01-17-2013 #2
How about:
This handles multiple file names so I guess it's fancier than you might need. If a file name doesn't contain "_tmp", it should just return the original name.Code:$ cat untemp for file in "$@" do newfile=$(echo "$file" | sed 's/_tmp//') echo $newfile done $ untemp proj_request_tmp_table proj_request_table $
- 01-18-2013 #3Just Joined!
- Join Date
- Oct 2012
- Posts
- 22
Thank you so much!!!!!
- 01-18-2013 #4Just Joined!
- Join Date
- Oct 2012
- Posts
- 22
I applied your code but output looks like that "output: afaweiraw printout"
would you mind take a look my code? i need help
Code:#! /bin/ksh # $1 -< proj_request_tmp_table #param1=$1 param1='proj_request_tmp_table' export param1 newfile =$(echo "$param1" | sed 's/_tmp//') export newfile echo "output: $newfile print out" #--end of script
- 01-18-2013 #5
The biggest problem I see in your script is the space between newfile and the assignment operator in the statement calling sed. When I took it out, I think I got the behavior you expected. You can't have a space like that on either side of the assignment operator. If the value you're assigning to the variable has leading spaces, you're going to have to express the spaces (and perhaps the entire value) inside quotes or something.
Note that the exports are unnecessary. They don't hurt but they don't help in this case. Since you're just using the variables locally in the script, there's no need to export them. You only need to export if you're invoking an external script or command and you want it to run with that variable as an environment variable.
- 01-18-2013 #6
are you just trying to remove tmp from the name?


Reply With Quote

