Solved

how to AWK with the fix lenght

Posted on 2011-03-08
6
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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