Delete word from the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete word from the file
# 8  
Old 08-28-2015
To get output in a file, put it in a file.

Code:
while something
do
...
done < file > outfile

# 9  
Old 08-31-2015
I've one last question.

With this code I can get a .txt file as required. However, I would like to get a fresh file everyday instead of the appending the the same .txt file.

Code:
#!/bin/sh
for i in "/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_"$(date +%Y-%m-%d --date "4 day ago")"_tmptcmsaslva2_"*".log"
do  
       echo "${i##*/}" < output_file.txt
done

e.g. If I run today I may get 3 records in output_file.txt. When I run tomorrow I should not get the same records along with current day's records in output_file.txt rather I should get only current day's records in output_file.txt
# 10  
Old 08-31-2015
Hello Ram,

There are two ways to complete this request.
I- Keep getting a output file which has particular day's date in it's name itself, so each day files will be unique and different names.
Code:
#!/bin/sh
DATE=`date +%y%m%d`
 for i in "/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_"$(date +%Y-%m-%d --date "4 day ago")"_tmptcmsaslva2_"*".log"
do  
       echo "${i##*/}" >>  "output_file_"$DATE".txt"
done

II- Each day check for file named output_file.txt and rename it to that's day's date and create a output file with name output_file.txt.
Code:
#!/bin/sh
DATE=`date +%y%m%d`
if [[ -f output_file.txt ]]
then
      mv output_file.txt "output_file_"$DATE".txt"
fi
for i in "/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_"$(date +%Y-%m-%d --date "4 day ago")"_tmptcmsaslva2_"*".log"
do  
       echo "${i##*/}" >>  output_file.txt
done

Thanks,
R. Singh

Last edited by RavinderSingh13; 08-31-2015 at 06:26 AM..
This User Gave Thanks to RavinderSingh13 For This Post:
# 11  
Old 08-31-2015
There is other way which I found nowSmilie. Just I put a remove command at the beginning of the script like below.
Code:
#!/bin/sh
rm output_file.txt
for i in "/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_"$(date +%Y-%m-%d --date "1 day ago")"_tmptcmsaslva2_"*".log"
do
    echo "${i##*/}" >> output_file.txt
done

Now I'm looking to capture the script execution in log files (.log)
# 12  
Old 08-31-2015
Quote:
Originally Posted by Ram Kumar_BE
.
.
.
Code:
#!/bin/sh
for i in "/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_"$(date +%Y-%m-%d --date "4 day ago")"_tmptcmsaslva2_"*".log"
do  
       echo "${i##*/}" < output_file.txt
done

.
.
.
With this code snippet, you won't get any output_file.txt. Replacing < with > , you'd get an output_file.txt with exactly the last .log file name encountered.
Putting the > output_file.txt right after the done, as proposed by Corona688 in post#8, you'll have a new output file every time you run the snippet.
# 13  
Old 08-31-2015
Script is working fine. Earlier there was a line feed issue.

Now I was looking to get a script execution log file.

Last edited by Ram Kumar_BE; 08-31-2015 at 07:28 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete Word between two Char.

HI Guys, I have Input:- A nput A.txt 000100/port_xcu_dev_6/port_0_dev_7 000100/port_xcu_dev_6/port_1_dev_10 000100/port_xcu_dev_2/port_2_dev_8 000100/port_xcu_dev_3/port_3_dev_11 000100/port_xcuv_9/port_4_dev_9 ... (3 Replies)
Discussion started by: pareshkp
3 Replies

2. Shell Programming and Scripting

Search the word to be deleted and delete lines above this word starting from P1 to P3

Hi, I have to search a word in a text file and then I have to delete lines above from the word searched . For eg suppose the file is like this: Records P1 10,23423432 ,77:1 ,234:2 P2 10,9089004 ,77:1 ,234:2 ,87:123 ,9898:2 P3 456456 P1 :123,456456546 P2 abc:324234 (2 Replies)
Discussion started by: vsachan
2 Replies

3. UNIX for Dummies Questions & Answers

Script to delete a word based on position in a file

Hi, I am new to unix. I want to delete 2 words placed at position say for example at 23rd and 45th position in a line. I used sed but couldnt achieve this. Example: the file contains 2 lines 12345 98765 "12345" 876 12345 98765 "64578" 876 I want to delete " placed at position 13 and 19... (4 Replies)
Discussion started by: nbks2u
4 Replies

4. Shell Programming and Scripting

How to delete the last word in a file?

Hi All, I have a file with the data as below. In this i want to delete the last word. Could you pls help me. $INSTALL_HOME/lib/fm_voucher_pol.so $INSTALL_HOME/source/sys/fm_apn_pol/fm_apn_pol_device_set_state.c In the above two lines i want to delete fm_voucher_pol.so and... (5 Replies)
Discussion started by: girish.raos
5 Replies

5. Shell Programming and Scripting

Delete everything after/before a word in a file

I'm looking for a command that will read a file listing information and delete everything after a certain word is found. I also may need to search the file and delete everything before a certain word. The file would contains fields of information like below repeating for the entire file; Name... (5 Replies)
Discussion started by: daveisme
5 Replies

6. Shell Programming and Scripting

Delete character from a word

Friends, I'm looking for a command that delete the first tho caractere in a word. Here is an exp : I want to replace "20091001" by "091001" or "replace" by "place" Thx, (13 Replies)
Discussion started by: newpromo
13 Replies

7. Shell Programming and Scripting

To find a word in a file and delete the file

Hi, I need to find a word in a file, and I need to delete the file where the word resides on the file. I did try with the grep -H "word" using the find command, but no luck. (6 Replies)
Discussion started by: gsiva
6 Replies

8. Shell Programming and Scripting

Delete repeated word in text file

Hi expert, I am using C shell. And i trying to delete repeated word. Example file.txt: BLUE YELLOW RED VIOLET RED RED BLUE WHITE YELLOW BLACK and i wan store the output into a new file: BLUE (6 Replies)
Discussion started by: vincyoxy
6 Replies

9. UNIX for Dummies Questions & Answers

Delete a word

i have created the following input script CREATE OR REPLACE VIEW MMSSENDAVGUPLOADTIME_GN AS sp_strip_mean_value_type.get_val(MMSSENDAVGUPLOADTIME) MMSSENDAVGUPLOADTIME_val sp_strip_mean_value_type.get_val(MMSSENDAVGUPLOADTIME) MMSSENDAVGUPLOADTIME_counter select... (1 Reply)
Discussion started by: gseptember
1 Replies

10. Shell Programming and Scripting

How to delete a word from a file?

Hi All, I want to delete a word from file. How to do that. I have file that contains the following Information. EntityName:alba00r1.mis.amat.com OverallStatus:Minor IfName:Gi1/0 EntityName:alba00r1.mis.amat.com ] OverallStatus:Normal IfName:Se0/0/0... (4 Replies)
Discussion started by: ntgobinath
4 Replies
Login or Register to Ask a Question