Folder contents getting appended as strings while redirecting file contents to a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Folder contents getting appended as strings while redirecting file contents to a variable
# 1  
Old 03-28-2013
Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below


Code:
# sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/'

Resource List : <br>
*************************** 1. row ***************************<br>
          ID: 11337<br>
AVAILABILITY: RED<br>
    PLATFORM: qe-z1-mm CCM-Hardware<br>
   SORT_NAME: HARDWARE<br>
 DESCRIPTION: <br>
*************************** 1. row ***************************<br>
          ID: 15761<br>
AVAILABILITY: N/A<br>
    PLATFORM: 216<br>
   SORT_NAME: BG<br>
 DESCRIPTION: <br>
*************************** 1. row ***************************<br>

now if i try to store this into a variable something like this happens

Code:
vk=$( sed -n "/CCM-HQE-ResourceHealthCheck:/,/---------/{/CCM-HQE-ResourceHealthCheck:/d;/---------/d;p;}" TACHCAutomation.OutputZ$zoneCounter | sed 's/$/<br>/'  )


echo $vk

Resource List : <br> @ htmlGEN.sh myOutput.html myScript.sh sample.sh some.html TACHCAutomation.OutputZ1 TACHCAutomation.OutputZ2 TACHCAutomation.OutputZ3 TACHCAutomation.OutputZ4 TACHCAutomationOutput.html TACHCAutomationtemp1.txt TACHCAutomationtemp2.txt test.output test.output.html test.output_orig threshold.conf txt2HTML.sh txt2HTML.sh_backup_mar28 txt2HTML.sh_backup2 txt2HTML.sh_backup3 txt2HTML.sh_backup4 txt2HTML.sh_orig vk 1. row ***************************<br>
.
.
.
.ect ect

thse are nothing but folder contents where these files are... any workaround available for this.. i need to store the output in variable itself and not file...
# 2  
Old 03-28-2013
It is stored right, but when you echo an unquoted string, substitution happens.

It takes the *'s to mean 'expand filenames' and flattens all white space when you echo an unquoted string. Try this:

Code:
echo "$vk"

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 03-29-2013
thanks a lot Corona.. quotes solved the issue.. gosh i have so much to learn,.... :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX utility to find difference in folder, file and contents of file against a base version

Hi, I am trying to find out whether there are any Unix utilities that compares folders, files and contents within the file and provides a comprehensive report. The comparison can be against base version of a folder and file with content. Can you please let me know of such a utility? Thanks,... (6 Replies)
Discussion started by: Sripathi_ks
6 Replies

2. Shell Programming and Scripting

How to copy all the contents of a list of files present in a folder to a particular file?

Hi All, I want to copy all the contents of a list of files in a folder to a particular file. i am using following command: cat dir/* >> newFile.txtIt's not working. Could you please help? Thanks, Pranav (3 Replies)
Discussion started by: Pranav Bhasker
3 Replies

3. Shell Programming and Scripting

Replace Contents between 2 strings in a file with contens of another file

Please I want to replace all the contents beween "Section" and "Ensection" in file1 with all contents in file2. Example: file1: Section "Screen" DefaultDepth 24 SubSection "Display" Depth 8 ViewPort 0 0 Modes "1024x768" "800x600" "640x480" EndSubsection SubSection "Display" Depth... (9 Replies)
Discussion started by: powelltallen
9 Replies

4. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

5. UNIX for Dummies Questions & Answers

Replacing a particular string in all files in folder and file contents

I need to replace all filesnames in a folder as well as its content from AK6 to AK11. Eg Folder has files AK6-Create.xml, AK6-system.py etc.. the files names as well as contents should be changes to AK9-Create.xml, AK9-system.py etc All files are xml and python scripts. ---------- Post... (0 Replies)
Discussion started by: Candid247
0 Replies

6. UNIX for Dummies Questions & Answers

How to search two strings in a file and print the contents in between to a file

I have a file called po.txt. Here is the content of the file: <!DOCTYPE PurchaseOrderMessage (View Source for full doctype...)> - <PurchaseOrder> - <Header> <MessageId>cdb3062b-685b-4cd5-9633-013186750e10</MessageId> <Timestamp>2011-08-01T13:47:23.536-04:00</Timestamp> </Header> -... (4 Replies)
Discussion started by: webbi
4 Replies

7. Shell Programming and Scripting

replace a string with contents of a txt file containing multiple lines of strings

Hello everyone, ive been trying to replace a string "kw01" in an xml file with the contents of a txt file having multiple lines. im a unix newbie and all the sed combinations i tried resulted to being garbled. Below is the contents of the txt file: RAISEDATTIME --------------------... (13 Replies)
Discussion started by: 4dirk1
13 Replies

8. Shell Programming and Scripting

How to read contents of a file into variable :(

My file is in this format : username : student information : default shell : student ID Eg : joeb:Joe Bennett:/bin/csh:1234 jerryd:Jerry Daniels:/bin/csh:2345 deaverm: Deaver Michelle:/bin/bash:4356 joseyg:Josey Guerra:/bin/bash:8767 michaelh:Michael Hall:/bin/ksh:1547 I have to... (1 Reply)
Discussion started by: dude_me5
1 Replies

9. UNIX for Dummies Questions & Answers

compare 2 file contents , if same delete 2nd file contents

Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents..... I try with "diff"...... but confusion how to use "diff" with if ---else Thanking you (5 Replies)
Discussion started by: krishnampkkm
5 Replies

10. Shell Programming and Scripting

Storing the contents of a file in a variable

There is a file named file.txt whose contents are: +-----------------------------------+-----------+ | Variable_name | Value | +-----------------------------------+-----------+ | Aborted_clients | 0 | | Aborted_connects | 25683... (6 Replies)
Discussion started by: proactiveaditya
6 Replies
Login or Register to Ask a Question