01-31-2013
Quote:
Originally Posted by
cnrj
I am using Ksh
*sigh*
this is only half the necessary information: there is Korn shell 88 and Korn shell 93 and they differ in some respects (ksh93 has some features ksh88 has not). Which one are you using? And while you are at it: the name and version of the OS sometimes also matters, so you better [i]always[/i state this information ideally at the top of any new thread.
bakunin
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have two files:
One is a list of numbers:
1
5
6
7
10
The second is a very long string
abcdefghijklmno......1234567890
I'd like to print a new file with a 5 character substring that starts at each the positions listed in the 1st file:
such as:
abcde (4 Replies)
Discussion started by: dcfargo
4 Replies
2. Shell Programming and Scripting
hi
i need to name a file with a substring of a another file name.
i.e. if the old filename is abc.txt , the new filename should be abc_1.txt
i should get the substring of the file name and then name the new one
please let me know how to do it (4 Replies)
Discussion started by: adityamahi
4 Replies
3. Shell Programming and Scripting
Hi,
I have a folder list as below, I want to write a script to return a list like:
CASTLE_BU_20080801
CAUSEWAY_BU_20080801
HUNGHOM_BU_20080801
:
:
Can anyone help?
Thanks!
Victor Cheung
List of the folder:
# ls
CASTLE_BU_20080801.DMP OFFICE_MY1_BU_20080801.DMP... (1 Reply)
Discussion started by: victorcheung
1 Replies
4. Shell Programming and Scripting
I'm new to shell scripting and am trying to write a small script that pulls a substring out of a file that has a few lines of text in it. The file will eventually have a lot of text, I just put a few lines in it for testing purposes.
Anyway, this is what I have so far...
#!/bin/ksh
... (4 Replies)
Discussion started by: enator45
4 Replies
5. Shell Programming and Scripting
Hi,
I have a file with a long string, in the format:
name1=value,name2=value2.....namen=valuen
I want to query the file and extract 'value2' ONLY. name2=value2 can exist anywhere within the file.
Can anyone help me please wth a suitable BASH command?
Many thanks,
Matt (4 Replies)
Discussion started by: mjwoodford
4 Replies
6. Shell Programming and Scripting
Hi,
In my shell script. I am reading all files in directory.
And say if the file names are as follows:
adio_idfl_201302_df.txt
dfa_201301_dll.ctl
dalkd_20130301.csv
I would like to extract the numeric piece of each file name and display as follows:
201302
201301
20130301
I... (9 Replies)
Discussion started by: pinnacle
9 Replies
7. UNIX for Dummies Questions & Answers
Hello,
I have in my backup folder, files with names convention like this :
randomFileNames_13-02-2014_23h13m09+1392333189
randomFileNames_14-02-2014_02h13m09+1392343989
randomFileNames_14-02-2014_04h13m09+1392351189
etc....
Base on timestamp at end of the filename, I would to delete all the... (7 Replies)
Discussion started by: thuyetti
7 Replies
8. Shell Programming and Scripting
Hello,
A question please.
A have a file that contains a string. Ex:
AAAABBCCCCCDDEEEEEEEEEEFF
I'd want to recover 2 substrings, 'BB' and 'FF' and then leave them in a new file.
Could anoyone help me please?
Thanks in advance (3 Replies)
Discussion started by: nolo41
3 Replies
9. Shell Programming and Scripting
Hello,
A question please.
A have a file that contains a string. Ex:
AAAABBCCCCCDDEEEEEEEEEEFF
I'd want to recover 2 substrings, 'BB' and 'FF' and then leave them in a new file.
From position 5, 2 caracters (ex:"BB") and from position 25, 2 caracters (ex:"FF") in a file.
Could anoyone help me... (3 Replies)
Discussion started by: nolo41
3 Replies
10. Shell Programming and Scripting
I want to merge the lines by matching substring of the first file with first column of the second file.
file1:
S00739A_ACAGTG_L001_R1.fq.gz
S00739A_ACAGTG_L001_R2.fq.gz
S00739B_GCCAAT_L001_R1.fq.gz
S00739B_GCCAAT_L001_R2.fq.gz
S00739D_GTGAAA_L001_R1.fq.gz
S00739D_GTGAAA_L001_R2.fq.gz... (14 Replies)
Discussion started by: yifangt
14 Replies
LEARN ABOUT CENTOS
shell-quote
SHELL-QUOTE(1) User Contributed Perl Documentation SHELL-QUOTE(1)
NAME
shell-quote - quote arguments for safe use, unmodified in a shell command
SYNOPSIS
shell-quote [switch]... arg...
DESCRIPTION
shell-quote lets you pass arbitrary strings through the shell so that they won't be changed by the shell. This lets you process commands
or files with embedded white space or shell globbing characters safely. Here are a few examples.
EXAMPLES
ssh preserving args
When running a remote command with ssh, ssh doesn't preserve the separate arguments it receives. It just joins them with spaces and
passes them to "$SHELL -c". This doesn't work as intended:
ssh host touch 'hi there' # fails
It creates 2 files, hi and there. Instead, do this:
cmd=`shell-quote touch 'hi there'`
ssh host "$cmd"
This gives you just 1 file, hi there.
process find output
It's not ordinarily possible to process an arbitrary list of files output by find with a shell script. Anything you put in $IFS to
split up the output could legitimately be in a file's name. Here's how you can do it using shell-quote:
eval set -- `find -type f -print0 | xargs -0 shell-quote --`
debug shell scripts
shell-quote is better than echo for debugging shell scripts.
debug() {
[ -z "$debug" ] || shell-quote "debug:" "$@"
}
With echo you can't tell the difference between "debug 'foo bar'" and "debug foo bar", but with shell-quote you can.
save a command for later
shell-quote can be used to build up a shell command to run later. Say you want the user to be able to give you switches for a command
you're going to run. If you don't want the switches to be re-evaluated by the shell (which is usually a good idea, else there are
things the user can't pass through), you can do something like this:
user_switches=
while [ $# != 0 ]
do
case x$1 in
x--pass-through)
[ $# -gt 1 ] || die "need an argument for $1"
user_switches="$user_switches "`shell-quote -- "$2"`
shift;;
# process other switches
esac
shift
done
# later
eval "shell-quote some-command $user_switches my args"
OPTIONS
--debug
Turn debugging on.
--help
Show the usage message and die.
--version
Show the version number and exit.
AVAILABILITY
The code is licensed under the GNU GPL. Check http://www.argon.org/~roderick/ or CPAN for updated versions.
AUTHOR
Roderick Schertler <roderick@argon.org>
perl v5.16.3 2010-06-11 SHELL-QUOTE(1)