- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Question regarding cat......
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 08:46 AM
06-29-2005 08:46 AM
Question regarding cat......
when given a variable containing "SanNonMAR2005". And that's all we have to work with.
I need to split the contents of the variable into 2 pieces (SanNon) and (MAR2005) and insert a "1" and a "2" where necessary to build the stmt above.
If InputFile is my variable then 'echo $Inputfile | cut -c1-6' would give me SanNon. That's about as far as I've gotten....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 09:00 AM
06-29-2005 09:00 AM
Re: Question regarding cat......
PT1=$(echo "${Inputfile}" | cut -c1-6)
PT2=$(echo "${Inputfile}" | cut -c7-)
V1="${PT1}1${PT2}"
echo "V1 = ${V1}"
V2="${PT1}2${PT2}"
echo "V2 = ${V2}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 09:01 AM
06-29-2005 09:01 AM
Re: Question regarding cat......
echo ${var#SanNon}
echo ${var%MAR*}
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 09:02 AM
06-29-2005 09:02 AM
Re: Question regarding cat......
Here's what you are looking for:
=============================================
Inputfile=SanNonMAR2005
echo $Inputfile | awk -F"M" 'BEGIN{OFS="M"} {print $1"1",$2}'
=============================================
the above code will give you "SanNon1MAR2005.txt". Replace the "1" in the awk command with the appropriate number (say 2) to build your cat command.
hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 10:09 AM
06-29-2005 10:09 AM
Re: Question regarding cat......
Try this:
-----------------------------------
#!/usr/bin/sh
typeset -i STAT=1
typeset FNAME=''
typeset PT1=''
typeset MON=''
typeset YR=''
while [[ ${STAT} -ne 0 ]]
do
echo "Enter Filename: \c"
read FNAME
perl -e 'if ($ARGV[0] =~ /(.+)(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(\d{4})$/ ) { printf ("%s\t%s\t%s\n",$1,$2,$3); exit(0); } else { exit(1); }' "${FNAME}" | read PT1 MON YR
STAT=${?}
if [[ ${STAT} -ne 0 ]]
then
echo "Bad Format: FnameMONYYYY" >&2
fi
done
typeset CMD="cat ${PT1}1${MON}${YR}.txt ${PT1}2${MON}${YR}.txt > \
${PT1}${MON}${YR}"
echo "Cmd = \"${CMD}\""
exit ${STAT}
---------------------------------------
Note: The perl command including the read PT1 MON YR is all one line. The power of this approach is that it actually checks your filename for valid composition (valid monthname, 4 digit year). I've looked this over carefully and it should work. so that all you need to do is ${CMD} to actually exucute the built-up string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 04:49 PM
06-29-2005 04:49 PM
Re: Question regarding cat......
echo $InputFile | awk '{ printf("%s1%s2", substr($0, 1, 6), substr($0, 7));}'
-Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2005 07:49 PM
06-29-2005 07:49 PM
Re: Question regarding cat......
==============================================================
# export InputFile="SanNonMAR2005"
# echo $Inputfile | awk -F"M" '{system("cat "$1"1M"$2".txt "$1"2M"$2".txt > "$0)}'
==============================================================
This will execute the code you want, i.e.
# cat SanNon1MAR2005.txt SanNon2MAR2005.txt > SanNonMAR2005
cheers!