- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Putting spaces into a cut command output
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
Discussions
Discussions
Discussions
Forums
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
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
тАО07-18-2003 10:40 AM
тАО07-18-2003 10:40 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-18-2003 10:48 AM
тАО07-18-2003 10:48 AM
Re: Putting spaces into a cut command output
awk -F. '{print $1,$2,$3}'
will put spaces between all characters in your file
(you'll need to put the appropriate number of fields in ...not just $1,$2,$3)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-18-2003 10:50 AM
тАО07-18-2003 10:50 AM
Re: Putting spaces into a cut command output
cat your file | sed 's/ data / /g' #> another file
that is data with a leading and trailing space which means it won't catch if data is at the beginning or end of the line. and 6 spaces
sed 's/^data / /' #for beginning of line
sed 's/ data$/ /' #for end of line
these use 5 spaces.
altogether
sed -e 's/ data / /g' -e 's/^data / /' -e 's/ data$/ /'
just replace data with your characters and put in the appropriate number of spaces.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-18-2003 10:53 AM
тАО07-18-2003 10:53 AM
Re: Putting spaces into a cut command output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-18-2003 10:58 AM
тАО07-18-2003 10:58 AM
Solutioncut -c 1-2,5-10 < myfile | while read A B
do
echo "${A} ${B}"
done
but this will not work because cut will put everying in the list argument in ${A}.
This will work:
cat myfile | while read X
do
A=$(echo ${X} | cut -c 1-2)
B=$(echo ${X} | cut -c 5-10)
echo "${A} ${B}"
done
A better approach would be to create an awk script, my.awk
{
a = substr($0,1,2)
b = substr($0,5,6)
printf("%s %s\n",a,b)
}
then invoke it as
awk -f my.awk myfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-18-2003 10:59 AM
тАО07-18-2003 10:59 AM
Re: Putting spaces into a cut command output
I have a file with lines in it with data like this
0540000560583221010907500007477660505020711000000006
and I want to pull out charaters 13-23 and 44-52 with spaces between the first set of charaters and the last set. Also, the last set is the end of the line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-18-2003 11:03 AM
тАО07-18-2003 11:03 AM
Re: Putting spaces into a cut command output
#!/usr/bin/ksh
string="data"
numchar=${#string}
spaces=""
x=0
while (( $x < $numchar ))
do
spaces="$spaces "
done
cat yourfile |
sed -e 's/ '$string' / '$spaces' /g' -e 's/^'$string' / '$spaces' /' -e 's/ '$string'$/ '$spaces'/' > newfile
mv newfile yourfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-18-2003 11:08 AM
тАО07-18-2003 11:08 AM
Re: Putting spaces into a cut command output
cat file |
while read line
do
sting1=$(echo $line | cut 13-23)
string2=$(echo $line | cut 44-52)
echo $string1 $string2 >> newfile
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-18-2003 11:18 AM
тАО07-18-2003 11:18 AM
Re: Putting spaces into a cut command output
cat yourfile |
awk '{
a = substr($0,13,11)
b = substr($0,44,9)
printf("%s %s\n",a,b)
}'
sorry about the misdirected posts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-18-2003 11:40 AM
тАО07-18-2003 11:40 AM