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
Solved

how to AWK with the fix lenght

Posted on 2011-03-08
6
238 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using Grep to Find a file 8 99
remove a combination of patterns from a file 15 70
Script to modify multiple files in Ubuntu / CentOS 2 57
Parse DNS log 3 74
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 …
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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…

837 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