Solved

how to AWK with the fix lenght

Posted on 2011-03-08
6
237 Views
Last Modified: 2012-05-11
how to get the variable in the string with the fixed size?

callXXXmain="|111                                  |222             |4444    |"

TempXXX=$(echo $callXXXmain | awk -F "|" '{print substr($25,1,70)}')
TempXXX="111 "

the TempXXX i only can get "111 " without any space.... what i need to get is, the variable with the spacing ...
0
Comment
Question by:gagajanice
  • 3
  • 3
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 35078050
callXXXmain="|111                                  |222             |4444    |"
TempXXX=$(echo "$callXXXmain" | awk -F "|" '{print substr($25,1,70)}')
echo "$TempXXX"
0
 
LVL 84

Expert Comment

by:ozo
ID: 35078055
callXXXmain="|111                                  |222             |4444    |"
TempXXX=$(echo "$callXXXmain" | awk -F "|" '{print substr($2,1,70)}')
echo "$TempXXX"
0
 

Author Comment

by:gagajanice
ID: 35078127
hi.. thankx
but i need to make the TempXXX to get the lenght in size 70

TempXXX="111                                                                 "
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:gagajanice
ID: 35078167
but

calXXXmain="|ABC DDK KLD        |aji |123   |"
TempXXX=$(echo $calXXXmain | awk -F "|" '{print substr($2,1)}')
TempXXX="`printf "%-70s" $TempXXX`"

but after it.. become   error
TempXXX="ABC                              DDK                      KLD                                                  "
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 35079474
calXXXmain="|ABC DDK KLD        |aji |123   |"
TempXXX=$(echo $calXXXmain | awk -F "|" '{print substr($2,1)}')
TempXXX=`printf "%-70s" "$TempXXX"`
0
 

Author Comment

by:gagajanice
ID: 35093319
thank you... it can work very fine!!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question