Sponsored Content
Top Forums Shell Programming and Scripting awk print string with removing all spaces Post 302945094 by o1283c on Tuesday 26th of May 2015 06:51:07 AM
Old 05-26-2015
Hi Clx,

The input was come from a api command's output and the format as follows:
Code:
aaa1|bbbb1   | cc1   | dddd ddd1 |eee eee eee1|ff1|gg1|hh1|ii1|jj1
aaa2|bbbb2   | cc2   | dddd ddd2 |eee eee eee2|ff2|gg2|hh2|ii2|jj2
aaa3|bbbb3   | cc3   | dddd ddd3 |eee eee eee3|ff3|gg3|hh3|ii3|jj3

and I want to have the output from awk -F'|' '{print $1","$2","$3","$4","$5","$6","$7","$8","$9","$10}'` becomes:
Code:
aaa1,bbbb1,cc1,dddd ddd1,eee eee eee1,ff1,gg1,hh1,ii1,jj1
aaa2,bbbb2,cc2,dddd ddd2,eee eee eee2,ff2,gg2,hh2,ii2,jj2
aaa3,bbbb3,cc3,dddd ddd3,eee eee eee3,ff3,gg3,hh3,ii3,jj3

then finally set the output from awk to the variable Table (for some reasons that I don't want to use file so that's why I keep using pipe and then put all result records into a variable)

Paul

Last edited by rbatte1; 05-26-2015 at 01:20 PM.. Reason: Added CODE tags for data
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print arguments along with spaces using awk

Hi All, file_1.txt contains aaa bbbb hhhh vvvvv mmmmm iiiii What i want is to search for the first coloumn of each line using awk.i.e as below: awk '/aaa/ {printf(<>)}' file_1.txt The print part (<>) should contain all the values(or coloumns ) in the particular line(here it... (8 Replies)
Discussion started by: jisha
8 Replies

2. Shell Programming and Scripting

Removing spaces from string

I want a user to be able to paste in a string like "01 3F 20 1F" and have the script reformat it to "013F201F" to pass it on to the next step. I was trying to figure it out with awk but wasnt working well. Never mind, found answer. did not know about tr :) (7 Replies)
Discussion started by: ippy98
7 Replies

3. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

4. Shell Programming and Scripting

Print filenames with spaces using awk

Hello all, I want to list the file contents of the directory and number them. I am using la and awk to do it now, #ls |awk '{print NR "." $1}' 1. alpha 2. beta 3. gamma The problem I have is that some files might also have some spaces in the filenames. #ls alpha beta gamma ... (7 Replies)
Discussion started by: grajp002
7 Replies

5. Shell Programming and Scripting

Print the string between spaces

How to print the strings within a line between two spaces . <ns1:providerErrorCode>141</ns1:providerErrorCode> <ns1:providerErrorText>business_rule_exception-Server.404:Cannot proceed because the subscriber with phone number is either suspended or the account has an unpaid... (8 Replies)
Discussion started by: raghunsi
8 Replies

6. UNIX for Dummies Questions & Answers

Print files with spaces using awk

When I use: find . -ls | awk 'BEGIN { OFS = ";"} {print $1,$2,$11}'I get a nice result, yet the files with spaces in it show only the first word and all other characters after the blank space are not printed. e.g. 'file with a blank space' is printed file 'file_with a blank space' is... (7 Replies)
Discussion started by: dakke
7 Replies

7. Shell Programming and Scripting

Removing columns from awk '{ print $0 }'

I have a one-line command, lsusb | awk '{ $1=""; $2=""; $3=""; $4=""; $5=""; $6=""; print $0 }' It works, and gives the results I expect, I was just wondering if I am missing some easier way to nullify the first 6 column variables? Something like, lsusb | awk '{ $(1-6)=""; print $0 }' But... (10 Replies)
Discussion started by: AlphaLexman
10 Replies

8. Shell Programming and Scripting

awk for removing spaces

HI, I have a file with lot of blank lines, how can I remove those using awk?? Thanks, Shruthi (4 Replies)
Discussion started by: shruthidwh
4 Replies

9. UNIX for Dummies Questions & Answers

AWK print last field including SPACES

I have simple test.sh script, see below: bill_code=`echo $record | awk -F"|" '{print $1}'` Fullname=`echo $record | awk -F"|" '{print $3}'` email=`echo $record | awk -F\ '{print $4}'` The last field contains spaces: see csv below: A0222|Y|DELACRUZ|-cc dell@yahoo.com-cc support@yahoo.com ... (9 Replies)
Discussion started by: quay
9 Replies

10. Shell Programming and Scripting

awk - print columns with text and spaces

Hi, I'm using awk to print columns from a tab delimited text file: awk '{print " "$2" "$3" $6"}' file The problem I have is column 6 contains text with spaces etc which means awk only prints the first word. How can I tell awk to print the whole column content as column 6? Thanks, (10 Replies)
Discussion started by: keenboy100
10 Replies
apply(n)						       Tcl Built-In Commands							  apply(n)

__________________________________________________________________________________________________________________________________________________

NAME
apply - Apply an anonymous function SYNOPSIS
apply func ?arg1 arg2 ...? _________________________________________________________________ DESCRIPTION
The command apply applies the function func to the arguments arg1 arg2 ... and returns the result. The function func is a two element list {args body} or a three element list {args body namespace} (as if the list command had been used). The first element args specifies the formal arguments to func. The specification of the formal arguments args is shared with the proc com- mand, and is described in detail in the corresponding manual page. The contents of body are executed by the Tcl interpreter after the local variables corresponding to the formal arguments are given the val- ues of the actual parameters arg1 arg2 .... When body is being executed, variable names normally refer to local variables, which are cre- ated automatically when referenced and deleted when apply returns. One local variable is automatically created for each of the function's arguments. Global variables can only be accessed by invoking the global command or the upvar command. Namespace variables can only be accessed by invoking the variable command or the upvar command. The invocation of apply adds a call frame to Tcl's evaluation stack (the stack of frames accessed via uplevel). The execution of body pro- ceeds in this call frame, in the namespace given by namespace or in the global namespace if none was specified. If given, namespace is interpreted relative to the global namespace even if its name does not start with "::". The semantics of apply can also be described by: proc apply {fun args} { set len [llength $fun] if {($len < 2) || ($len > 3)} { error "can't interpret "$fun" as anonymous function" } lassign $fun argList body ns set name ::$ns::[getGloballyUniqueName] set body0 { rename [lindex [info level 0] 0] {} } proc $name $argList ${body0}$body set code [catch {uplevel 1 $name $args} res opt] return -options $opt $res } EXAMPLES
This shows how to make a simple general command that applies a transformation to each element of a list. proc map {lambda list} { set result {} foreach item $list { lappend result [apply $lambda $item] } return $result } map {x {return [string length $x]:$x}} {a bb ccc dddd} -> 1:a 2:bb 3:ccc 4:dddd map {x {expr {$x**2 + 3*$x - 2}}} {-4 -3 -2 -1 0 1 2 3 4} -> 2 -2 -4 -4 -2 2 8 16 26 The apply command is also useful for defining callbacks for use in the trace command: set vbl "123abc" trace add variable vbl write {apply {{v1 v2 op} { upvar 1 $v1 v puts "updated variable to "$v"" }}} set vbl 123 set vbl abc SEE ALSO
proc(n), uplevel(n) KEYWORDS
argument, procedure, anonymous function Tcl apply(n)
All times are GMT -4. The time now is 04:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy