Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7562365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:23:51+00:00 2026-05-30T13:23:51+00:00

Iam new to bach script. following is the code i used to search the

  • 0

Iam new to bach script. following is the code i used to search the name entered through command line and search the entered string in outputLog.txt .if found update the current system time of that name string.

In command line
[root@localhost desktop]# ./myscript.sh name1

Logone2.txt
name1 = Tue Jan  20 14:00 19 IST 2012 
name2 =Tue Jan  20 14:05 19 IST 2012 
name3 = Tue Jan  20 14:20 19 IST 2012 
name4 =Tue Jan 20 14:45 19 IST 2012 

My problem is while i trying to enter name1,it is updated with the current system time also its is appending as last entry.

 Eg:Logone2.txt
    name1 = Tue Feb    20 14:00 19 IST 2012 
    name2 =Tue Jan  20 14:05 19 IST 2012 
    name3 = Tue Jan  20 14:20 19 IST 2012 
    name4 =Tue Jan 20 14:45 19 IST 2012
    name1 = Tue Feb    20 14:00 19 IST 2012 (appended entry)

I only want to append the string with current system time if it is not found in the Logone2.txt.IF the string(name1) entered through command line is found in the Logone2.txt ,update the name with current system time as follows.

  Eg:Logone2.txt
name1 = Tue Feb    20 14:00 19 IST 2012 
name2 =Tue Jan  20 14:05 19 IST 2012 
name3 = Tue Jan  20 14:20 19 IST 2012 
name4 =Tue Jan 20 14:45 19 IST 2012

Here is the code iam using

#!/bin/bash
echo "${1} $(date)" >> /root/Desktop/scripts/Logone2.txt
fgrep "${1}" /root/Desktop/scripts/Logone2.txt && \ 
     sed -i "/${1}/ s/.*/${1} = $(date)/" /root/Desktop/scripts/Logone2.txt || \
echo "${1} $(date)" >> /root/Desktop/scripts/Logone2.txt
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:23:52+00:00Added an answer on May 30, 2026 at 1:23 pm

    if i got it right my first idea is to rewrite the entire file replacing name1 with sed. e.g.

    cat Logone2.txt | sed "s/^name1=.*/name1=`date`/g" > newfile.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam new to bash script programming. I want to implement a bash script deploymLog
iam using following function in my javascript code function AlphaSort(sort_type,cat_1,cat_2,cat_nm) { var len =
Iam using locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); String bestProvider =
Iam new to perl and trying out a sample code for my project. What
Iam new to c programming and needs some help. long *taskids[NUM_THREADS]; for(t=0; t<NUM_THREADS; t++)
Hi iam new to c++ and iam trying out this vector program and i
Iam quite new to functions in SQL and I would like to create a
Hi iam new to C# and have loaded the image in the picture box
Iam a php developer, and iam new to drupal.I have installed a drupal site.
How can I integrate aweber with codeigniter? Iam new to the aweber. I dont

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.