- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Cut command
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-04-2002 06:53 AM
06-04-2002 06:53 AM
Hi,
I??m writting a script ( tra.sh ) to read an input file ( file.txt ) and creates an output ( output.txt ). The problem is that the cut command that I??m using at the VAR4 is giving me a strange value, like this:
RJ-05000-RIO and not all the contents. How to read all and set the correct value at VAR4 ?
Regards,
R.Bassoi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2002 07:01 AM
06-04-2002 07:01 AM
Re: Cut command
The fault likes with this:
for VARS in $(cat file.txt)
This is because spacingsl be used to delimit the VARS when you cat file.txt, apart from newlines.
Do this instead:
#!/usr/bin/ksh
cat file.txt|while read a b c d e f g
do
VARS="$a $b $c $d $e $f $g"
VAR1=$(echo $VARS|cut -d";" -f1)
VAR2=$(echo $VARS|cut -d";" -f2)
VAR3=$(echo $VARS|cut -d";" -f3)
VAR4=$(echo $VARS|cut -d";" -f4)
VAR5=$(echo $VARS|cut -d";" -f5)
echo "CRECENTR,AREADG=INTRA-RJ-2,CARRIER=031,F_MOV=0,LOC_RF=$VAR4,OPERA_RF=31-
TELEMAR,PREFINT=$VAR1,PREFURB=$VAR2$VAR3,TARIF_RF=0100;" >> output.txt
done
exit 0
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2002 07:04 AM
06-04-2002 07:04 AM
Re: Cut command
Also remember to add double-quotes (") for your VAR1 to VAR5 i.e.
VAR1="..."
VAR2="..."
... and so forth
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2002 07:07 AM
06-04-2002 07:07 AM
Re: Cut command
This is because "for VARS in $(cat file.txt);do" is cutting by spaces try doing a sed before in order to substitute spaces by other character like "#":
sed 's/ /#/g' file.txt > file1.txt
for VARS in $(cat file1.txt);do
An then into the for undo the changes with:
VARSok=`echo | sed 's/#/ /g'`
An then use the new variable VARSok to cut.
Regards,
Justo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2002 07:09 AM
06-04-2002 07:09 AM
Re: Cut command
Tks Steve,
I forgot: Its possible to remove ( when is present ) the first 0 from the VAR1 ?
Tks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2002 07:12 AM
06-04-2002 07:12 AM
Re: Cut command
Yes, since there is only one zero and it is always at the first position:
echo $VAR1|cut -c2-
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2002 07:15 AM