Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Strip out number from wc output? Post 302910361 by somegeek on Thursday 24th of July 2014 12:43:08 AM
Old 07-24-2014
I'm currently performing this using a one liner in bash... I'm a bit of a script noob.

When I add in cat -e I now see the wc -l output(3 in this case) at the end of the line (woot - no more overlapping output) with the characters you mentioned:
Code:
^M       3$

---------- Post updated at 07:19 PM ---------- Previous update was at 07:09 PM ----------

I did some more poking and piping my echo statement to
Code:
tr -dc '[:print:]'

cleared things up. How can I go back and identify what was causing the issue or was it wc's inherent output formatting?

Appreciate the assitance.

---------- Post updated at 08:56 PM ---------- Previous update was at 07:19 PM ----------

Thinking something is getting through with the files I'm pulling from.

I perform this with some made up files with basic strings and all is well. No overlapping funkiness:
Code:
file1:
windows 7
application 1
application 2
application 3

file2:
windows 7
application 1
application 2
application 3
application 4
application 5



> ls * | while read a; do printf "$a $(egrep "windows" $a) $(egrep application $a | wc -l)\n";done
file1 windows 7       3
file2 windows 7       5

---------- Post updated at 09:43 PM ---------- Previous update was at 08:56 PM ----------

Figured this out with the files I'm working with... tr -d '\r' removed the carriage return but I wasn't sure where since it worked when I put it after the echo statement. Moved it back, one at a time and see it needed to remove that from the first command substitution. All good now. Nothing to do with wc from the look of it at this point... just my own skewed perception. Smilie

ls * | while read a; do printf "$a $(egrep "text" $a | tr -d '\r') $(egrep other_text $a | wc -l)\n";done

Thanks again.

Last edited by somegeek; 07-24-2014 at 12:32 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Strip lines off Streamed EDI Output

Attached is a streamed EDI ANSI X12 output where the segment terminator/delimiter is a tilde ~ character. Is it possible to do the following pseudo-code in a unix script (using either sed, awk and/or grep)? Open file StreamedOutput.txt Search for ISA and delete the data up to the tilde ~ char... (7 Replies)
Discussion started by: sapedi
7 Replies

2. Shell Programming and Scripting

KSH Output/Strip portion of file in HP-UX

I have a file, we'll call it file.txt. It has thousands of lines of all kinds of output at any given time (ie. foo bar foo bar) I need to copy out just a portion of the file from Point-A to Point-B. I'd like to save off just that portion to a file called test123xyz.txt. How do I do that? ... (7 Replies)
Discussion started by: austin881
7 Replies

3. Shell Programming and Scripting

find with given number and express output

file A eebbbeeeeee file B 4 Question is by file B and look into file A output is b awk -v v1=4 file B or something else (2 Replies)
Discussion started by: cdfd123
2 Replies

4. Shell Programming and Scripting

Extract particular number from the command output

Hi Folks, I want to use particular number as a variable output..Please find the below for scenario... Example 1:- Below output i want to use secondary group 9003 as a variable output $ id -a |awk -NF '{print $3}' groups=99(local),9003(testadmin) Else I want to use 2006 as a... (8 Replies)
Discussion started by: susindram
8 Replies

5. Shell Programming and Scripting

awk number output

Hi, I have a problem when doing calculations in awk. I want to add up a few numbers and output the result. testfile: 48844322.87 7500.00 10577415.87 3601951.41 586877.64 1947813.89 $ awk '{x=x+$1};END{print x}' testfile 6.55659e+07The problem is the number format. It should show... (3 Replies)
Discussion started by: Subbeh
3 Replies

6. Shell Programming and Scripting

Getting awk Output as number instead of String

Hi All, I have a file a.txt, content as mentioned below: 22454750 This data in this control file and I have a variable called vCount which contains a number. I need to extract the 22454750 from the above file and compare with the variable vCount. If match fine or else exit. ... (5 Replies)
Discussion started by: Arun Mishra
5 Replies

7. UNIX for Dummies Questions & Answers

The number of links, output of ls

hi: i am trying to understand the concept of the output of ls command, specifically "number of links" for a directory and got utterly confused: 1) when i made first directory in my home directory: dave@host:~:$ mkdir dir_l1 from the perspective of home directory, the link number for... (2 Replies)
Discussion started by: ipfreak
2 Replies

8. Shell Programming and Scripting

awk to output lines less than number

I am trying to output all lines in a file where $7 is less than 30. The below code does create a result file, but with all lines in the original file. The original file is tab deliminated is that the problem? Thank you :). awk 'BEGIN{FS=OFS=","} $7 < 30 {print}' file.txt > result.txt... (3 Replies)
Discussion started by: cmccabe
3 Replies

9. UNIX for Beginners Questions & Answers

How to output non-number lines with grep?

I want to check my data quality. I want to output the lines with non-number. I used the grep command: grep '' myfile.csv Since my file is csv file, I don't want to output the lines with comma. And I also don't want to output "." or space. But I still get the lines like the following:... (8 Replies)
Discussion started by: twotwo
8 Replies
Tcl_SubstObj(3tcl)					      Tcl Library Procedures						Tcl_SubstObj(3tcl)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_SubstObj - perform substitutions on Tcl objects SYNOPSIS
#include <tcl.h> Tcl_Obj * Tcl_SubstObj(interp, objPtr, flags) ARGUMENTS
Tcl_Interp *interp (in) Interpreter in which to execute Tcl scripts and lookup variables. If an error occurs, the interpreter's result is modified to hold an error message. Tcl_Obj *objPtr (in) A Tcl object containing the string to perform substitutions on. int flags (in) ORed combination of flag bits that specify which substitutions to perform. The flags TCL_SUBST_COM- MANDS, TCL_SUBST_VARIABLES and TCL_SUBST_BACKSLASHES are currently supported, and TCL_SUBST_ALL is pro- vided as a convenience for the common case where all substitutions are desired. _________________________________________________________________ DESCRIPTION
The Tcl_SubstObj function is used to perform substitutions on strings in the fashion of the subst command. It gets the value of the string contained in objPtr and scans it, copying characters and performing the chosen substitutions as it goes to an output object which is returned as the result of the function. In the event of an error occurring during the execution of a command or variable substitution, the function returns NULL and an error message is left in interp's result. Three kinds of substitutions are supported. When the TCL_SUBST_BACKSLASHES bit is set in flags, sequences that look like backslash substi- tutions for Tcl commands are replaced by their corresponding character. When the TCL_SUBST_VARIABLES bit is set in flags, sequences that look like variable substitutions for Tcl commands are replaced by the con- tents of the named variable. When the TCL_SUBST_COMMANDS bit is set in flags, sequences that look like command substitutions for Tcl commands are replaced by the result of evaluating that script. Where an uncaught "continue exception" occurs during the evaluation of a command substitution, an empty string is substituted for the command. Where an uncaught "break exception" occurs during the evaluation of a command substitution, the result of the whole substitution on objPtr will be truncated at the point immediately before the start of the command substitution, and no characters will be added to the result or substitutions performed after that point. SEE ALSO
subst(3tcl) KEYWORDS
backslash substitution, command substitution, variable substitution Tcl 8.4 Tcl_SubstObj(3tcl)
All times are GMT -4. The time now is 03:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy