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

  • SEARCH
  • Home
  • 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 9281327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:05:27+00:00 2026-06-18T18:05:27+00:00

I want a shell script that grabs my current screen resolution, (solved) searches a

  • 0

I want a shell script that

  1. grabs my current screen resolution, (solved)
  2. searches a file for the line containing the resolution setting,
  3. replaces the old resolution setting in the file with the current one

So far (thanks!) I’ve got the command for getting the current screen resolution data:

system_profiler SPDisplaysDataType | awk '/Resolution/ {
    print "screenwidth \""$2"\"";
    print "screenheight \""$4"\"";
}'

The lines that should be written to respectively begins with:

screenwidth "VALUE1"
screenheight "VALUE2"

How do I write the results to the file on the “VALUE” positions?

(I’m quite a beginner in the world of shell scripts)

  • 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-06-18T18:05:28+00:00Added an answer on June 18, 2026 at 6:05 pm

    If I understood you right,

    sys..|grep..|awk ..$2   is new widht
    sys..|grep..|awk ..$4   is new height
    

    you want to replace value1/2 in old file with new values from above lines

    -- old file  --
    screenwidth "VALUE1"
    screenheight "VALUE2"
    

    then you could do in one shot:

    sys..|grep..|awk 'NR==FNR{w=$2;h=$4;next}/screenwidth/{$0="screenwidth \""w"\"";} /screenheight/{$0="screenheight \""h"\""}1' -  oldfile
    

    see this test example:

    #I simulate your sys..|grep.. with echo
    
    kent$  cat old.txt
    foo
    screenwidth "VALUE1"
    screenheight "VALUE2"
    bar
    
    kent$  echo "foo 200 bar 400"|awk 'NR==FNR{w=$2;h=$4;next}/screenwidth/{$0="screenwidth \""w"\"";} /screenheight/{$0="screenheight \""h"\""}1' -  old.txt    
    foo
    screenwidth "200"
    screenheight "400"
    bar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a shell script that outputs filenames (one per line). I want to
Hello i want a simple shell script that find the name of the file
I want to create a shell script that will create a pre-formatted file and
I want to associate the .exe file extension with a shell script that launches
I want to run a shell script on startup by google ,I found that
I want to open html files from a shell script. I know that Ubuntu
I have the below line in the unix shell script. I want to exclude
I want to run script file on android Shell using Native C program. I
I want a simple testing shell script that launches a program N times in
I want to simulate a tree command using Shell Script that displays all the

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.