awk to txt provide strange character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to txt provide strange character
# 1  
Old 02-15-2012
awk to txt provide strange character

Hi all,

I executed this script
Code:
top -n 1 | awk '{ if (NR==3) print $2 }'

and it will give me in console
Code:
'31.6%us,'

however, if I put the same script in txt file
Code:
top -n 1 | awk '{ if (NR==3) print $2 }' >> test.txt

when I open the test.txt
I see
Code:
31.6%ESC(BESC[mESC[39;49mus,ESC(BESC[mESC[39;49mESC(BESC[m

I just actually need the 31.6 % to be written there, but some strange characters are rendered there. Can anyone help me with this?

*thank you moderator for editing this post

Thank you

Moderator's Comments:
Mod Comment Use code tags, see PM.

Last edited by peuceul; 02-15-2012 at 11:42 AM.. Reason: code tags
# 2  
Old 02-15-2012
top is using ANSI esccape sequences to format the output to the screen. Some versions of top have an option to write directly to a file rather than the tty. This means those sequences are not there in the file. Batch mode may help.

Check your documentation or try
Code:
top -h

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in

Hi dears i have text file like this: INPUT.txt 001_1_173 j nuh ]az 001_1_174 j ]esma. nuh ]/.xori . . . and have another text like this TABLE.txt j j nuh word1... (6 Replies)
Discussion started by: alii
6 Replies

2. UNIX for Dummies Questions & Answers

Replace character string in txt file using input file(S)

Hi I have a large txt file on my AIX server and I need to replace some text using two other files. So filename1 has about 500 lines similar to: txtcode SYStem100 I have the string I want to change in string2 and the new stringname in string3. Does anyone know a way of doing this? I have... (1 Reply)
Discussion started by: Grueben
1 Replies

3. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

4. Shell Programming and Scripting

Joining lines in TXT file based on first character

Hi, I have a pipe delimeted text file where lines have been split over 2 lines and I need to join them back together. For example the file I have is similar to the following: aaa|bbb |ccc ddd|eee fff|ggg |hhh I ideally need to have it looking like the following aaa|bbb|ccc ddd|eee... (5 Replies)
Discussion started by: fuji_s
5 Replies

5. Shell Programming and Scripting

awk append fileA.txt to growing file B.txt

This is appending a column. My question is fairly simple. I have a program generating data in a form like so: 1 20 2 22 3 23 4 12 5 43 For ever iteration I'm generating this data. I have the basic idea with cut -f 2 fileA.txt | paste -d >> FileB.txt ???? I want FileB.txt to grow, and... (4 Replies)
Discussion started by: theawknewbie
4 Replies

6. UNIX for Advanced & Expert Users

"╭─ " Character combo in $PATH causes strange autocompletion behavior in zsh

I've posted about this before, but only recently narrowed the problem down to a specific cause. Ok, first of all, the behavior: It occurs when autocompletion brings up its list (not when there is only a single option). Basically, if I were to type, say, cd ~/<TAB> I would get something... (2 Replies)
Discussion started by: marshaul
2 Replies

7. Programming

Strange character added when reading to buffer with length of 12

Hi all, I got trouble with reading and writing ( to standard input/output, file, socket whatever...). I will briefly describe it by giving this example. I want to read a long string from keyboard but i don't know how long it is b4. So i need to know the number of character i will read first.... (6 Replies)
Discussion started by: tazan_007
6 Replies

8. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies

9. UNIX for Dummies Questions & Answers

echo "ABC" > file1.txt file2.txt file3.txt

Hi Guru's, I need to create 3 files with the contents "ABC" using single command. Iam using: echo "ABC" > file1.txt file2.txt file3.txt the above command is not working. pls help me... With Regards / Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies

10. UNIX for Dummies Questions & Answers

there was a strange character(^M) been added automatically in UNIX

I used Notepad to compile my txt file and then I transferred this file to UNIX. When I use vi to open the file, I found that at the end of each line there was a "^M" character. In the original txt file there was not this character. Why this character would been added automatically in UNIX? (4 Replies)
Discussion started by: Jasmine
4 Replies
Login or Register to Ask a Question